Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-77377: Ensure multiprocessing SemLock is valid for spawn-based Process before serializing it#107275

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
pitrou merged 5 commits intopython:mainfromalbanD:fix-issue-77377
Aug 23, 2023

Conversation

albanD
Copy link
Contributor

@albanDalbanD commentedJul 25, 2023
edited by bedevere-bot
Loading

This fixes both the example in the initial report#77377 and other reports on the PyTorch repo.

Note that as far as I can tell, all objects that lead to segfault with mixed context are all caused by SemLock created with fork sent over a Spawn process. That's why it is the only object updated here and the only pair of ctx covered. Let me know if I'm mistaken and I can find a way to update other objects as well.
Also windows behavior is not changed here (and thus not tested).

Please let me know if the error message and/or the test are not appropriate and I can work on improving them.

@bedevere-bot
Copy link

Most changes to Pythonrequire a NEWS entry.

Please add it using theblurb_it web app or theblurb command-line tool.

@@ -6155,3 +6155,9 @@ class SemLock(_multiprocessing.SemLock):
name = f'test_semlock_subclass-{os.getpid()}'
s = SemLock(1, 0, 10, name, False)
_multiprocessing.sem_unlink(name)

def test_semlock_mixed_context(self):
Copy link
Member

Choose a reason for hiding this comment

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

Does this test actually need to be Linux-only? (seeSemLockTests definition above)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

This is indeed also relevant on macos. Moved the test to be able to test it there.
On windows, there is only spawn, so there is no way to get "mixed" context.


def test_semlock_mixed_context(self):
queue = multiprocessing.get_context("fork").Queue()
p = multiprocessing.get_context("spawn").Process(target=close_queue, args=(queue,))
Copy link
Member

Choose a reason for hiding this comment

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

Do we also want to test with "forkserver" method?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Good catch! Added it.
It now ensure that all cases work. Let me know if that properly covers all the cases you had in mind.

@@ -5421,6 +5421,24 @@ def test_preload_resources(self):
print(err)
self.fail("failed spawning forkserver or grandchild")

@unittest.skipIf(sys.platform == "win32", "Only Spawn on windows so no risk of mixing")
Copy link
Member

Choose a reason for hiding this comment

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

Style nit, but can you try to wrap the lines below around ~80 characters max?

albanD reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Updated!
Thanks for the update on the blurb, I wasn't sure what to put there

@pitroupitrou added needs backport to 3.11only security fixes needs backport to 3.12only security fixes labelsAug 23, 2023
@pitroupitrouenabled auto-merge (squash)August 23, 2023 20:26
@pitroupitrou merged commit1700d34 intopython:mainAug 23, 2023
@miss-islington
Copy link
Contributor

Thanks@albanD for the PR, and@pitrou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

albanD reacted with thumbs up emoji

@bedevere-bot
Copy link

GH-108377 is a backport of this pull request to the3.12 branch.

@bedevere-botbedevere-bot removed the needs backport to 3.12only security fixes labelAug 23, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestAug 23, 2023
…ed Process before serializing it (pythonGH-107275)Ensure multiprocessing SemLock is valid for spawn Process before serializing it.Creating a multiprocessing SemLock with a fork context, and then trying to pass it to a spawn-created Process, would segfault if not detected early.---------(cherry picked from commit1700d34)Co-authored-by: albanD <desmaison.alban@gmail.com>Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>Co-authored-by: Antoine Pitrou <pitrou@free.fr>
@bedevere-bot
Copy link

GH-108378 is a backport of this pull request to the3.11 branch.

@bedevere-botbedevere-bot removed the needs backport to 3.11only security fixes labelAug 23, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestAug 23, 2023
…ed Process before serializing it (pythonGH-107275)Ensure multiprocessing SemLock is valid for spawn Process before serializing it.Creating a multiprocessing SemLock with a fork context, and then trying to pass it to a spawn-created Process, would segfault if not detected early.---------(cherry picked from commit1700d34)Co-authored-by: albanD <desmaison.alban@gmail.com>Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>Co-authored-by: Antoine Pitrou <pitrou@free.fr>
@albanDalbanD deleted the fix-issue-77377 branchAugust 23, 2023 21:03
pitrou added a commit that referenced this pull requestAug 23, 2023
…sed Process before serializing it (GH-107275) (#108378)gh-77377: Ensure multiprocessing SemLock is valid for spawn-based Process before serializing it (GH-107275)Ensure multiprocessing SemLock is valid for spawn Process before serializing it.Creating a multiprocessing SemLock with a fork context, and then trying to pass it to a spawn-created Process, would segfault if not detected early.---------(cherry picked from commit1700d34)Co-authored-by: albanD <desmaison.alban@gmail.com>Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>Co-authored-by: Antoine Pitrou <pitrou@free.fr>
Yhg1s pushed a commit that referenced this pull requestAug 23, 2023
…sed Process before serializing it (GH-107275) (#108377)gh-77377: Ensure multiprocessing SemLock is valid for spawn-based Process before serializing it (GH-107275)Ensure multiprocessing SemLock is valid for spawn Process before serializing it.Creating a multiprocessing SemLock with a fork context, and then trying to pass it to a spawn-created Process, would segfault if not detected early.---------(cherry picked from commit1700d34)Co-authored-by: albanD <desmaison.alban@gmail.com>Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>Co-authored-by: Antoine Pitrou <pitrou@free.fr>
pitrou added a commit that referenced this pull requestAug 30, 2023
…108568)gh-107275 introduced a regression where a SemLock would fail being passed along nested child processes, as the `is_fork_ctx` attribute would be left missing after the first deserialization.---------Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>Co-authored-by: Antoine Pitrou <pitrou@free.fr>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestAug 30, 2023
… case (pythonGH-108568)pythongh-107275 introduced a regression where a SemLock would fail being passed along nested child processes, as the `is_fork_ctx` attribute would be left missing after the first deserialization.---------(cherry picked from commitadd8d45)Co-authored-by: albanD <desmaison.alban@gmail.com>Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>Co-authored-by: Antoine Pitrou <pitrou@free.fr>
pitrou added a commit that referenced this pull requestAug 30, 2023
…e case (GH-108568) (#108692)gh-107275 introduced a regression where a SemLock would fail being passed along nested child processes, as the `is_fork_ctx` attribute would be left missing after the first deserialization.---------(cherry picked from commitadd8d45)Co-authored-by: albanD <desmaison.alban@gmail.com>Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>Co-authored-by: Antoine Pitrou <pitrou@free.fr>
Yhg1s pushed a commit that referenced this pull requestAug 30, 2023
…e case (GH-108568) (#108691)gh-108520: Fix bad fork detection in nested multiprocessing use case (GH-108568)gh-107275 introduced a regression where a SemLock would fail being passed along nested child processes, as the `is_fork_ctx` attribute would be left missing after the first deserialization.---------(cherry picked from commitadd8d45)Co-authored-by: albanD <desmaison.alban@gmail.com>Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>Co-authored-by: Antoine Pitrou <pitrou@free.fr>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@pitroupitroupitrou left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@albanD@bedevere-bot@miss-islington@pitrou

[8]ページ先頭

©2009-2025 Movatter.jp