Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

socket connection retry mechanism doesn't work in some situations #186

Open
weyou opened this issue Mar 15, 2021 · 2 comments
Open

socket connection retry mechanism doesn't work in some situations #186

weyou opened this issue Mar 15, 2021 · 2 comments
Labels

Comments

@weyou
Copy link

weyou commented Mar 15, 2021

It looks like the socket connection retry mechanism doesn't work in some situations.

    def _conn_request(self, conn, request_uri, method, body, headers):
        i = 0
       ...
        while i < RETRIES:
            i += 1        # <------ here variable i becomes 1
            try:
                if conn.sock is None:
                    conn.connect()
                conn.request(method, request_uri, body, headers)
                ...
            except http.client.HTTPException:
                if conn.sock is None:
            ...

The global variable RETRIES is hardcoded into 2 currently. So the following code will never be executed since i always greater or equal than RETRIES - 1

                    if i < RETRIES - 1:
                        conn.close()
                        conn.connect()
                        continue
                    else:
                        conn.close()
                        raise
                if i < RETRIES - 1:
                    conn.close()
                    conn.connect()
                    continue

Maybe httplib2 allow user to change the value of httplib2.RETRIES. then above code block is reasonable.

But the second place:

            try:
                response = conn.getresponse()
            except :
            ...

The i always greater than 0, so the following code block will never be executed.

            except (socket.error, http.client.HTTPException):
                conn.close()
                if i == 0:
                    conn.close()
                    conn.connect()
                    continue
@temoto
Copy link
Member

temoto commented Mar 15, 2021

Yes, it is dead code. Thank you.

It's better in Python2 version

                if i < RETRIES - 1:

https://github.com/httplib2/httplib2/blob/master/python2/httplib2/__init__.py#L1603-L1610

@temoto temoto added the bug label Mar 15, 2021
@monluk
Copy link

monluk commented May 23, 2022

Wouldn't it be better to remove "- 1" from the lines pointed in the bug report, so that there is "i < RETRIES"?
There are still people using that version and Python 2.

monluk added a commit to monluk/httplib2 that referenced this issue May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants