Skip to content
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

Tests fail with "OSError: AF_UNIX path too long" because socket paths exceed max length (107 bytes) #661

Merged
merged 1 commit into from
Dec 28, 2023

Conversation

cjntaylor
Copy link
Contributor

Splitting apart into a separate PR

Unix socket tests were failing with OSError: AF_UNIX path too long. The paths generated by pytest's tmp_path_factory fixture on macOS exceed the system max socket path length.

On macOS, the unix socket path length limit is 107 bytes; the base temp directory of /private/var/folders combined with the subdirectories added by tmp_path_factory generates paths regularly exceeding this limit by 10+ bytes. Linux also has this limit (108 bytes), but because it's almost always rooted at /tmp or /var/tmp it's unlikely to trigger this error. These limits are discussed more here: python/cpython#93852

A simple workaround was to use tempdir.TemporaryDirectory for socket paths. Even on macOS, these paths are short enough that they shouldn't trigger this error, while still using standard tempdir conventions/locations.

I'm unsure why these path lengths aren't an issue on the macOS CI instances; it's very odd they're not. The only major difference I can find is that I'm running Ventura (macOS 13) vs the CI's Monterey (macOS 12); otherwise my pytest version matches up exactly. I also don't see anything in the pytest commit history indicating a change to how tmp_path_factory locations are generated.

@agronholm
Copy link
Owner

Out of curiosity, what kinds of paths are you getting from tmp_path_factory?

docs/versionhistory.rst Outdated Show resolved Hide resolved
@cjntaylor
Copy link
Contributor Author

Out of curiosity, what kinds of paths are you getting from tmp_path_factory?

They look like this:

/private/var/folders/0w/hxs339xd1jx78kt6gpy0b8_w0000gp/T/pytest-of-cjntaylor/pytest-80/unix50/socket
/private/var/folders/0w/hxs339xd1jx78kt6gpy0b8_w0000gp/T/pytest-of-cjntaylor/pytest-80/unix51/socket
/private/var/folders/0w/hxs339xd1jx78kt6gpy0b8_w0000gp/T/pytest-of-cjntaylor/pytest-80/unix52/socket
/private/var/folders/0w/hxs339xd1jx78kt6gpy0b8_w0000gp/T/pytest-of-cjntaylor/pytest-80/unix53/socket

These are short enough to not throw AF_UNIX errors. I must have run the tests enough to increase the counts enough to push the path past 107 bytes. Explains why the CI works - it's tearing down it's temp folder each run so those counts will never get that high

Up to you if you still think this is an issue; it's a little close for comfort for me but the average person would probably not run into it 🤷‍♂️

@agronholm
Copy link
Owner

Looks uncomfortably close to the limit still.

@agronholm agronholm merged commit 1af2601 into agronholm:master Dec 28, 2023
16 checks passed
@cjntaylor cjntaylor deleted the pytest-socket-path branch December 28, 2023 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants