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

workers/gthread: Remove locks + one event queue + general cleanup #3157

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sylt
Copy link

@sylt sylt commented Feb 17, 2024

The main purpose is to remove complexity from gthread by:

  • Removing the lock for handling self._keep and self.poller. This is possible since we now do all such manipulation on the main thread instead. When a connection is done, it posts a callback through the PollableMethodCaller which gets executed on the main thread.

  • Having a single event queue (self.poller), as opposed to also managing a set of futures. This fixes Gunicorn gthread deadlock #3146 (although there are more minimal ways of doing it).

There are other more minor things as well:

  • Renaming some variables, e.g. self._keep to self.keepalived_conns.
  • Remove self-explanatory comments (what the code does, not why).
  • Remove fiddling with connection socket block/not blocked.

Some complexity has been added to the shutdown sequence, but hopefully for good reason: it's to make sure that all already accepted connections are served within the grace period.

The main purpose is to remove complexity from gthread by:

* Removing the lock for handling self._keep and self.poller. This is
  possible since we now do all such manipulation on the main thread
  instead. When a connection is done, it posts a callback through the
  PollableMethodCaller which gets executed on the main thread.

* Having a single event queue (self.poller), as opposed to also
  managing a set of futures. This fixes benoitc#3146 (although there are
  more minimal ways of doing it).

There are other more minor things as well:

* Renaming some variables, e.g. self._keep to self.keepalived_conns.
* Remove self-explanatory comments (what the code does, not why).
* Just decide that socket is blocking.

Some complexity has been added to the shutdown sequence, but hopefully
for good reason: it's to make sure that all already accepted
connections are served within the grace period.
self.set_accept_enabled(False)

# ... but try handle all already accepted connections within the grace period
graceful_timeout = time.time() + self.cfg.graceful_timeout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to #1967 this should use a monotonic clock, as the timeout is specified in seconds, with no regard for UTC sync or leap second.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gunicorn gthread deadlock
3 participants