Skip to content

test_final_symlink_backend_refuses_to_lock fails on x86_64-musl #731

Description

@AnInternetTroll

Hi, I would like to update filelock from 3.18.0 to 3.32.6, but I am getting an error when running the test_final_symlink_backend_refuses_to_lock test on musl. This runs as expected on glibc

Running on void-linux
Github action log:
https://github.com/void-linux/void-packages/actions/runs/34152095704/job/102974909519

Relevant snippet:

=================================== FAILURES ===================================
__________________ test_final_symlink_backend_refuses_to_lock __________________

tmp_path = PosixPath('/tmp/pytest-of-luca/pytest-0/test_final_symlink_backend_ref0')

    @NEEDS_FCNTL  # pragma: needs fcntl
    @_NEEDS_O_NOFOLLOW  # pragma: needs o-nofollow
    def test_final_symlink_backend_refuses_to_lock(tmp_path: Path) -> None:
        (tmp_path / "target").write_text("")
        (tmp_path / "link").symlink_to(tmp_path / "target")
        # Keeping the final symlink a distinct key is safe because the backend still refuses to lock through it. O_NOFOLLOW
        # reports the refusal as ELOOP on Linux and macOS, and as EFTYPE ("inappropriate file type") on NetBSD.
        with pytest.raises(OSError, match=r"Too many levels of symbolic links|symbolic link|Inappropriate file type"):
>           FileLock(str(tmp_path / "link")).acquire()

tests/test_filelock.py:2046: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.xbps-testdir/1789063565/usr/lib/python3.14/site-packages/filelock/_api.py:1059: in acquire
    self._poll_until_acquired(
.xbps-testdir/1789063565/usr/lib/python3.14/site-packages/filelock/_api.py:1220: in _poll_until_acquired
    self._acquire_with_fork_tracking()
.xbps-testdir/1789063565/usr/lib/python3.14/site-packages/filelock/_api.py:1278: in _acquire_with_fork_tracking
    self._acquire()
.xbps-testdir/1789063565/usr/lib/python3.14/site-packages/filelock/_unix.py:70: in _acquire
    missing_flock = self._acquire_native()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <filelock._unix.UnixFileLock object at 0x7fc6be8ec260>

    def _acquire_native(self) -> tuple[int, OSError] | None:
        ensure_directory_exists(self.lock_file)
        # Open without O_TRUNC and defer truncation and fchmod until after flock succeeds: a contender that loses
        # the lock must not truncate the holder's file (erasing caller diagnostics) or change its mode. The winner
        # truncates and normalizes mode once it owns the lock (#591).
        open_flags = os.O_RDWR
        if (o_nofollow := getattr(os, "O_NOFOLLOW", None)) is not None:
            open_flags |= o_nofollow
        open_flags |= os.O_CREAT
        open_mode = self._open_mode()
        try:
>           fd = os.open(self.lock_file, open_flags, open_mode)
E           OSError: [Errno 40] Symbolic link loop: '/tmp/pytest-of-luca/pytest-0/test_final_symlink_backend_ref0/link'

.xbps-testdir/1789063565/usr/lib/python3.14/site-packages/filelock/_unix.py:85: OSError

During handling of the above exception, another exception occurred:

tmp_path = PosixPath('/tmp/pytest-of-luca/pytest-0/test_final_symlink_backend_ref0')

    @NEEDS_FCNTL  # pragma: needs fcntl
    @_NEEDS_O_NOFOLLOW  # pragma: needs o-nofollow
    def test_final_symlink_backend_refuses_to_lock(tmp_path: Path) -> None:
        (tmp_path / "target").write_text("")
        (tmp_path / "link").symlink_to(tmp_path / "target")
        # Keeping the final symlink a distinct key is safe because the backend still refuses to lock through it. O_NOFOLLOW
        # reports the refusal as ELOOP on Linux and macOS, and as EFTYPE ("inappropriate file type") on NetBSD.
>       with pytest.raises(OSError, match=r"Too many levels of symbolic links|symbolic link|Inappropriate file type"):
E       AssertionError: Regex pattern did not match.
E        Regex: 'Too many levels of symbolic links|symbolic link|Inappropriate file type'
E        Input: "[Errno 40] Symbolic link loop: '/tmp/pytest-of-luca/pytest-0/test_final_symlink_backend_ref0/link'"

tests/test_filelock.py:2045: AssertionError
=========================== short test summary info ============================
FAILED tests/test_filelock.py::test_final_symlink_backend_refuses_to_lock - A...
============ 1 failed, 1454 passed, 55 skipped in 174.00s (0:02:53) ============

PS: I am unfamiliar with the filelock library, so please let me know if I need to put in more info or anything :)

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions