This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: _GLOBAL_DEFAULT_TIMEOUT remains as an object() in HTTPConnection and the connection hangs
Type: behavior Stage: resolved
Components: IO Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: orsenthil Nosy List: juanjux, orsenthil
Priority: normal Keywords:

Created on 2011-06-29 11:18 by juanjux, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg139406 - (view) Author: Juanjo Alvarez (juanjux) Date: 2011-06-29 11:18
I was testing a jsonrpc server using a small Python client. I noticed that sometimes when the RPC returned some long test, the response object returned by URLOpener.open(), in my case an HTTPResponse, would hang about 70% of the time when calling read() on a RPC method returning more text than usual (a string of about 4000 bytes).

Investigating it I noticed that on HTTPConnection.connect, the self.timeout value was "object". I tried to hardcode some value on the method first line, changing the "self.timeout" for "5":

self.sock = socket.create_connection((self.host,self.port),self.timeout, self.source_address)

Then suddenly the call to the RPC works 100% of the time, and I don't mean that it timeouts, it just works and doesn't hangs. So the workaround that I'm using is to call socket.setdefaulttimeout in my client code.

I saw that the default value in HTTPConnection for self.timeout is socket._GLOBAL_DEFAULT_TIMEOUT which is initialized as an "object()" and remains that way on my HTTPConnection.connect call. My guess is that when the RPC call is not very fast, the system checks the socket timeout and then it hangs if the value is an object, so the longer the text returned by the RPC, the higher the chance that the read() hangs.
msg139407 - (view) Author: Juanjo Alvarez (juanjux) Date: 2011-06-29 11:19
PS: This only happens to my on Windows XP, works perfectly under Linux.
msg140544 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2011-07-17 22:38
Would you like to give an example snippet (server+client) which can help reproduce this behavior?
msg393183 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2021-05-07 13:37
The _GLOBAL_DEFAULT_TIMEOUT usage is an established pattern with socket module. https://github.com/python/cpython/blob/main/Lib/socket.py#L805

This is not a bug and we don't have a good reproducible step mentioned in the report.
History
Date User Action Args
2022-04-11 14:57:19adminsetgithub: 56650
2021-05-07 13:37:47orsenthilsetstatus: open -> closed
resolution: not a bug
messages: + msg393183

stage: test needed -> resolved
2013-12-17 20:26:33serhiy.storchakasetstage: test needed
2011-07-17 22:38:25orsenthilsetassignee: orsenthil

messages: + msg140544
nosy: + orsenthil
2011-06-29 11:19:17juanjuxsetmessages: + msg139407
2011-06-29 11:18:39juanjuxcreate