gh-153279: Don't unlink another process's shared memory block on failed attach#153280
Open
uguraka wants to merge 1 commit into
Open
gh-153279: Don't unlink another process's shared memory block on failed attach#153280uguraka wants to merge 1 commit into
uguraka wants to merge 1 commit into
Conversation
…n failed attach SharedMemory.__init__ called self.unlink() from its OSError cleanup handler unconditionally. On the attach path (create=False) this destroyed a block owned by another process when mmap() failed (e.g. ENOMEM). The cleanup now only closes the file descriptor and unlinks the block only when it was created in the failing call. Because the block has not been registered with the resource tracker yet at that point, it is unlinked directly to avoid a spurious UNREGISTER (which raised KeyError in the resource tracker on the create path).
This file contains hidden or 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.
SharedMemory.__init__calledself.unlink()from itsOSErrorcleanuphandler unconditionally:
On the attach path (
create=False) this permanently destroyed a block ownedby another process when
mmap()failed (e.g.ENOMEMunder memory pressure),since
unlink()callsshm_unlink().The cleanup now only closes the file descriptor, and unlinks the block only
when it was created in the failing call. Because the block has not been
registered with the resource tracker at that point (
register()runs after thetry/except), it is unlinked directly rather than throughunlink(), whichavoids a spurious
UNREGISTERthat raisedKeyErrorin the resource trackeron the
create=Truepath.Added regression tests for both the attach and create failure paths; the attach
test fails without the fix.