GeezerVison is showing github.com — Tests fail with "OSError: AF_UNIX path too long" if TMPDIR path is longer than 107 bytes · Issue #93852 · python/cpython
Tests fail with "OSError: AF_UNIX path too long" if TMPDIR path is longer than 107 bytes #93852DescriptionThe Python test suite has multiple tests on AF_UNIX sockets. They create a temporary socket path. Example with test_socketserver:
return tempfile.mktemp(prefix='unix_socket.')
The problem is that if the temporary directory is too long, creating a socket with this path fails with "OSError: AF_UNIX path too long". On Linux, sun_path is 107 bytes.
With my PR #93817, TMPDIR becomes something like (...)/test_python_157983_æ/test_python_worker_243024_æ_tmpdir/. For example, the path /home/vstinner/python/main/build/test_python_157983_æ/test_python_worker_243024_æ_tmpdir/unix_socket.xxxxxxxx is 11 bytes long, longer than the limit of 107 bytes.
I see different options:
- Use a relative path
- Create a temporary socket path in the current directory rather than in TMPDIR
- Skip tests if AF_UNIX path is too long
Activityvstinner commented on Jun 15, 2022 Tested affected by this issue:
- test_asyncio
- test_logging: test_udp_reconnection()
- test_socket
- test_socketserver
kumaraditya303 commented on Jun 15, 2022 I like the second option: Create a temporary socket path in the current directory rather than in TMPDIR serhiy-storchaka commented on Jun 16, 2022 I suggest to create TMPDIR for workers in the parent TMPDIR instead of CWD.
For some tests it can be better if TMPDIR and CWD are not subdirectories of one other, or if they are on different partitions, or use different filesystems. TMPDIR by default uses a filesystem optimized for temporary files. It can also be mounted with some special options, like noatime, and it is worth to have ability to test with them. vstinner commented on Jun 16, 2022 I wrote PR #93914 to fix this issue.
First, I wrote a complicated check to convert OSError("AF_UNIX path too long") to unittest.SkipTest. But then I modified the function to use the current directory and so the path has always a reasonable length (around 27 ASCII characters). It no longer depends on TMPDIR env var. My check is no longer:
def create_unix_domain_name():
name = tempfile.mktemp(prefix=prefix, suffix='.sock')
# Skip the test if the path is too long for AF_UNIX.
# Linux has a limit of 107 bytes.
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
try:
sock.bind(name)
except OSError as exc:
msg = str(exc)
if msg != "AF_UNIX path too long":
raise
msg = f'create_unix_domain_name(): {msg}: {name}'
raise unittest.SkipTest(msg) from None
except PermissionError:
# Ignore permission error if the AF_UNIX socket cannot be bound.
# The caller will handle the error.
pass
finally:
sock.close()
if os.path.exists(name):
os.unlink(name)
return namevstinner commented on Jun 17, 2022 vapier commented on Sep 27, 2022 Reacted by ridhachahed and wymli added a commit that references this issue on Jan 30, 2024This issue will close once commit 0a06645 is merged into the 'master' branch.0a06645
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|