-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Force gevent connected socket to blocking mode #1616
Force gevent connected socket to blocking mode #1616
Conversation
Thank you for providing such detailed information and a patch. The patch is simple and it sounds like it would work, but do you think that the assumption Gunicorn makes about the socket being blocking is a bad one? Should we discuss any alternative changes? |
I was also concerned about that but came to the conclusion its probably ok. This gets a bit confusing since we are talking about blocking sockets that in the gevent world aren't necessarily really blocking anything. My thoughts:
|
Thanks for all that analysis. I agree with you. It does sound like it would fix #880, too. At least one comment there suggests that changing the socket timeout fixed the problem. |
…ed-socket Force gevent connected socket to blocking mode
Timeout is already set in HttpClient. The reason for removal is issue with gunicorn and gevent as described here benoitc/gunicorn#1616
Timeout is already set in HttpClient. The reason for removal is issue with gunicorn and gevent as described here benoitc/gunicorn#1616
Timeout is already set in HttpClient. The reason for removal is issue with gunicorn and gevent as described here benoitc/gunicorn#1616
The gevent worker assumes sockets are running in blocking mode. The current code forces the listening socket into blocking mode here. But the connected socket is not forced to blocking mode. Therefore if other code has set the default socket timeout with a call to
setdefaulttimeout
it will be set as the connected socket's timeout in the gevent initialization code here.The gevent worker relies on the keepalive timeout to close idle connections. Setting the default timeout below the keepalive timeout causes the worker to run in a undefined mode. I believe this may fix the issues in #880 but it was not clear if everyone having that issue were also calling
setdefaulttimeout
. In our particular case we are callingsetdefaulttimeout
which caused sockets to close before the keepalive expired. This causes a bunch of socket timeout error messages and potentially 504 errors with AWS ELBs.