-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Prevent gthread connection reset on max-requests restart #3039
Draft
christianbundy
wants to merge
16
commits into
benoitc:master
Choose a base branch
from
christianbundy:fix-gh-3038
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
We want to support TCP connections that haven't sent data, so 0ebb73a was merged to remove the assumption that all connections are readable. Instead of reading from the connection immediately, we use the selector event loop to determine when to read from the connection. This means that the
while self.alive
loop inself.run()
needs to run twice to handle a single HTTP request:self.poller.select()
and see the 'listener is readable' event, which prompts us to callself.accept()
. This creates a connection, but does not read from it. Instead,self.accept()
callsself.poller.register()
so that the connection is handled as soon as it's readable.self.poller.select()
again, but this time we'll see the 'connection is readable' event, which prompts us to callself.on_client_socket_readable()
. This handles the HTTP request and sends a response.Problem
We reset connections when we call
accept()
on connections, but notrecv()
. This happens when we reachself.max_requests
and setself.alive = False
, which prevents us from continuing through thewhile self.alive
loop.There are two related bugs, which are also important to fix:
self.nr_conns < self.worker_connections
before running any callbacks, but consider the case whereself.nr_conns == 9
,self.worker_connections == 10
, and we receive twenty callbacks to accept connections.self.poller.select()
if we pass theself.nr_conns < self.worker_connections
condition, so if we hit the limit with only speculative TCP requests then we'll never read any data from the connections.Solution
Revert 0ebb73a. I've tried a handful of different clever ways of resolving this, but I haven't been able to find one, and 'the server doesn't reset connections on restart' is significantly more important to me than 'the server can hold lots of speculative TCP connections'.
Fixes: #3038