GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||
GeezerVison is showing github.com — bpo-6721: Sanitize logging locks while forking by gpshead · Pull Request #4071 · python/cpython Conversation
|
| Acquire a thread lock for serializing access to the underlying I/O. | ||
| """ | ||
| self.lock = threading.RLock() | ||
| os.register_at_fork(before=self.acquire, |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This may register an arbitrary number of callbacks across an application's lifetime, also it makes the handles eternal by keeping a reference to all of them. Instead, we could have a global WeakSet of handlers and a single set of callbacks that iterate over the live handlers.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Another option would be a before=lambda acquire=weakref.WeakMethod(self.acquire): acquire()()... I'm used to applications that don't go creating tons of logging.Handler instances and throwing them away all over the place. :)
I think I'll go with the WeakSet approach to avoid an every growing list of callables in that strange Handler discarding application case...
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@gpshead Please come back to this patch during the sprint! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
8d51698 to
caa3e6f
Compare
caa3e6f to
a0c2cfb
Compare
Now it fails on the previous code and is fixed by the logging changes. The test now uses a thread to hold the locks during the fork in a synchronized manner. Due to mixing of fork and a thread there is potential for deadlock in the child process. buildbots and time will tell if this actually manifests itself in this test or not. :/
|
A regression test that actually catches the bug and is fixed by this change has been added. Due to mixing of fork and a thread there is potential for deadlock |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
bpo-6721: When os.fork() was called while another thread holds a logging lock, the child process may deadlock when it tries to log. This fixes that by acquiring all logging locks before fork and releasing them afterwards. A regression test that fails before this change is included. Within the new unittest itself: There is a small _potential_ due to mixing of fork and a thread in the child process if the parent's thread happened to hold a non-reentrant library call lock (malloc?) when the os.fork() happens. buildbots and time will tell if this actually manifests itself in this test or not. :/ A functionality test that avoids that would be a challenge. An alternate test that isn't trying to produce the deadlock itself but just checking that the release and acquire calls are made would be the next best alternative if so. (cherry picked from commit 1900384) Co-authored-by: Gregory P. Smith <[email protected]>
|
GH-9291 is a backport of this pull request to the 3.7 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
bpo-6721: When os.fork() was called while another thread holds a logging lock, the child process may deadlock when it tries to log. This fixes that by acquiring all logging locks before fork and releasing them afterwards. A regression test that fails before this change is included. Within the new unittest itself: There is a small _potential_ due to mixing of fork and a thread in the child process if the parent's thread happened to hold a non-reentrant library call lock (malloc?) when the os.fork() happens. buildbots and time will tell if this actually manifests itself in this test or not. :/ A functionality test that avoids that would be a challenge. An alternate test that isn't trying to produce the deadlock itself but just checking that the release and acquire calls are made would be the next best alternative if so. (cherry picked from commit 1900384) Co-authored-by: Gregory P. Smith <[email protected]> [Google]
There was an error while loading. Please reload this page.
|
Just a heads up: We have reverted this commit in Fedora's Python package (version 3.7.1), because it rendered our graphical installers not bootable. This may have just exposed some bug in the installer or it may have introduced a regression. We are currently investigating the problem with Fedora QA and the installer developers and we will open a BPO issue if we find out a simple reproducer. Details: https://bugzilla.redhat.com/show_bug.cgi?id=1644936 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.