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.

@sylt sylt force-pushed the gthread-cleanup branch 2 times, most recently from 17e7abf to 04243f3 Compare February 18, 2024 17:24
@benoitc benoitc self-assigned this Mar 26, 2024
gunicorn/workers/gthread.py Outdated Show resolved Hide resolved
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.
* Use time.monotonic() for timeouts in gthread.

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.
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
4 participants