Skip to content

Fix RuntimeError caused by logging in the SIGCHLD signal handler#2667

Closed
BoasKluiving wants to merge 1 commit into
benoitc:masterfrom
BoasKluiving:fix-non-reentrant-logging-in-signal-handler
Closed

Fix RuntimeError caused by logging in the SIGCHLD signal handler#2667
BoasKluiving wants to merge 1 commit into
benoitc:masterfrom
BoasKluiving:fix-non-reentrant-logging-in-signal-handler

Conversation

@BoasKluiving

Copy link
Copy Markdown

This PR is to fix an issue introduced by b695b49. This issue is also described in #2564. The problem is that we are logging something in the signal handler, which is not reentrant.

The issue occurs if Gunicorn happens to be logging something (for example here) and gets interrupted by SIGCHLD at that moment. This invokes the signal handler handle_chld() (here), which calls reap_workers().

reap_workers() however logs a warning here, causing the following RuntimeError:
RuntimeError: reentrant call inside <_io.BufferedWriter name='<stderr>'>

Operations on BufferedWriter are unfortunately not reentrant, so we can only fix this by (a) not logging in the signal handler or (b) only setting a flag in signal handler and do the processing later.

This PR fixes the problem by removing the log message in the signal handler.

@javabrett

Copy link
Copy Markdown
Collaborator

@BoasKluiving thanks for the PR. b695b49 was reverted by 76f8da2 having the same effect, so closing this PR.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants