GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #93852

New issue
Copy link
New issue
Copy link
Closed
Closed
Tests fail with "OSError: AF_UNIX path too long" if TMPDIR path is longer than 107 bytes#93852
Copy link
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@vstinner
vstinner
opened on Jun 15, 2022
Issue body actions

The 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

Activity

  1. vstinner
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Jun 15, 2022
  2. vstinner commented on Jun 15, 2022

    @vstinner
    vstinner
    on Jun 15, 2022
    MemberAuthor
    More actions

    Tested affected by this issue:

    • test_asyncio
    • test_logging: test_udp_reconnection()
    • test_socket
    • test_socketserver
  3. kumaraditya303 commented on Jun 15, 2022

    @kumaraditya303
    kumaraditya303
    on Jun 15, 2022
    Contributor
    More actions

    I like the second option: Create a temporary socket path in the current directory rather than in TMPDIR

  4. serhiy-storchaka commented on Jun 16, 2022

    @serhiy-storchaka
    serhiy-storchaka
    on Jun 16, 2022
    Member
    More actions

    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.

  5. vstinner commented on Jun 16, 2022

    @vstinner
    vstinner
    on Jun 16, 2022
    MemberAuthor
    More actions

    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 name
  6. vstinner
    added a commit that references this issue on Jun 17, 2022

    gh-93852: Add test.support.create_unix_domain_name() (#93914)

    c5b750d
  7. vstinner commented on Jun 17, 2022

    @vstinner
    vstinner
    on Jun 17, 2022
    MemberAuthor
    More actions

    Fixed by #93914

  8. vstinner
    closed this as completedon Jun 17, 2022
  9. serhiy-storchaka
    added a commit that references this issue on Jun 26, 2022

    Revert 30935 defer bpo45162 to 312 (#94285)

    1ffde3e
  10. vapier commented on Sep 27, 2022

    @vapier
    vapier
    on Sep 27, 2022
    More actions

    On Linux, sun_path is 107 bytes.

    for posterity, this is incorrect. Linux supports 108 bytes.
    https://man7.org/linux/man-pages/man7/unix.7.html#BUGS

    Reacted by ridhachahed and wymli
  11. SamuelMarks
    added a commit that references this issue on Jan 30, 2024

    [Lib/tempfile.py] Replace `_mkstemp_inner` and carefully percolate `r…

    This issue will close once commit 0a06645 is merged into the 'master' branch.
    0a06645
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.