Repository navigation
gh-149527: fix creation of temporary socket files post GH-148578 #149597
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
Merged
picnixz
merged 11 commits into
python:main
from
picnixz:fix/forkserver/path-too-long-149527
Oct 22, 2026
+89
−18
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
77c28e3
gh-149527: fix creation of temporary socket files post GH-148578
picnixz ab905ba
Update Lib/multiprocessing/util.py
picnixz 6a74bea
add tests
picnixz 6a78f3f
Merge branch 'main' into fix/forkserver/path-too-long-149527
picnixz 0bed495
amend
picnixz 3388fa1
Merge branch 'main' into fix/forkserver/path-too-long-149527
picnixz 6da8c2a
Update Lib/multiprocessing/util.py
picnixz e930a6a
Update Lib/multiprocessing/util.py
picnixz 59dacf9
fix tests on macOS
picnixz 094971f
Merge branch 'main' into fix/forkserver/path-too-long-149527
picnixz 5f4add5
Update test_misc.py
picnixz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,47 @@ | ||
| import os | ||
| import re | ||
| import unittest | ||
| from multiprocessing.util import _SUN_PATH_MAX | ||
| from test._test_multiprocessing import install_tests_in_module_dict | ||
| from test.support import os_helper, script_helper | ||
|
|
||
| install_tests_in_module_dict(globals(), 'forkserver', exclude_types=True) | ||
|
|
||
|
|
||
| class TestForkServerConfiguration(unittest.TestCase): | ||
| def test_respect_sun_path_max(self): | ||
| # Ensure that the calculation for temporary filepath lengths is correct. | ||
| # See https://github.com/python/cpython/issues/149527. | ||
|
|
||
| cmd = '''if 1: | ||
| from multiprocessing.connection import arbitrary_address | ||
| from multiprocessing.util import get_temp_dir | ||
| if __name__ == "__main__": | ||
| print(get_temp_dir()) | ||
| print(arbitrary_address("AF_UNIX")) | ||
| ''' | ||
| with os_helper.temp_dir() as root: | ||
| self.assertLess(len(root), _SUN_PATH_MAX) | ||
| _, out, _ = script_helper.assert_python_ok('-c', cmd, TMPDIR=root) | ||
| res = out.decode().strip().splitlines() | ||
| self.assertEqual(len(res), 2) | ||
|
|
||
| # get_temp_dir() with a TMPDIR that has a too large length ends up | ||
| # NOT being used as it is not possible to use it. In particular, | ||
| # the corresponding path will fallback to one of the "built-in" | ||
| # ones such as '/tmp', '/var/tmp', or '/usr/tmp'. | ||
| root_regex = "|".join(map(re.escape, [root, "/tmp", "/var/tmp", "/usr/tmp"])) | ||
|
|
||
| temp_pymp = res[0] | ||
| self.assertLess(len(temp_pymp), _SUN_PATH_MAX) | ||
| temp_pymp_regex = os.path.join(root_regex, r"pymp-\w{8}") | ||
| self.assertRegex(temp_pymp, temp_pymp_regex) | ||
|
|
||
| temp_sock = res[1] | ||
| self.assertLess(len(temp_sock), _SUN_PATH_MAX) | ||
| temp_sock_regex = os.path.join(temp_pymp_regex, r"sock-[0-9a-fA-F]{12}") | ||
| self.assertRegex(temp_sock, temp_sock_regex) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() |
3 changes: 3 additions & 0 deletions
3
Misc/NEWS.d/next/Library/2026-05-09-12-58-04.gh-issue-149527.hX36Yh.rst
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| :mod:`multiprocessing`: fix creation of temporary socket files following | ||
| :gh:`137335` (`PR#148578 <https://github.com/python/cpython/pull/148578>`__ | ||
| and corresponding backports). Patch by Bénédikt Tran. |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.