Repository navigation
test_glob: test_selflink() fails randomly on Linux #109959
Copy link
Copy link
Closed
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytestsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
AMD64 RHEL8 Refleaks 3.x:
0:09:26 load avg: 9.08 [406/463/1] test_glob failed (1 failure) -- running (7): (...)
beginning 6 repetitions
123456
.....test test_glob failed -- Traceback (most recent call last):
File "/home/buildbot/buildarea/3.x.cstratak-RHEL8-x86_64.refleak/build/Lib/test/test_glob.py", line 396, in test_selflink
self.assertIn(path, results)
AssertionError:
'dir/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/' not found in
{'dir/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/',
'dir/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/',
'dir/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/',
'dir/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/',
'dir/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/',
'dir/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/',
'dir/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/',
'dir/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/',
'dir/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/'}
The tested path dir/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link has one less link/ than the first path of the test: 'dir/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/'.
# Tested path
>>> len('dir/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/'.split('/'))
33
# First (shorted) expected path
>>> len('dir/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/'.split('/'))
34
build: https://buildbot.python.org/all/#/builders/259/builds/892
Linked PRs
- gh-109959: Log the current directory in test_glob.test_selflink() #128122
- gh-109959: attempt to fix hypothesis tests for
test_glob#128255 - gh-109959: Skip test_glob.test_selflink() flaky test #128812
- [3.13] gh-109959: Skip test_glob.test_selflink() flaky test (GH-128812) #128821
- [3.12] gh-109959: Skip test_glob.test_selflink() flaky test (GH-128812) #128834
- gh-109959: Remove test_glob.test_selflink() #130551
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytestsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
vstinner commentedon Nov 8, 2023
I didn't see this failure recently, I close the issue.
encukou commentedon Jun 19, 2024
Seen recently in a PR CI run.
ncoghlan commentedon Jun 19, 2024
Dumping the expected value and the set content from the failed run.
The shortest value in the set has one more
link/entry than the expected value that the test is looking for, so it's definitely the same failure mode, but the absolute numbers are different (27 vs 28 here, rather than the 33 vs 34 that Victor saw):encukou commentedon Jun 19, 2024
I assume it gets up to a max path length, so the OS & CWD will affect that number.
ncoghlan commentedon Jun 19, 2024
That was my first thought too, but it doesn't seem to be the case, since all the paths in the set were accessible on disk (the set being checked is derived from the glob result). The largest value in the
setwill be dictated by the OS and CWD, but the missing value isn't the largest one, it's somewhere in the middle. In the latest failure, the remaining 15 iterations would have worked:I also confirmed both tracebacks are pointing at the same assertion:
cpython/Lib/test/test_glob.py
Line 396 in ae36cd1
cpython/Lib/test/test_glob.py
Line 553 in a86e625
To get the reported failures:
ncoghlan commentedon Jun 19, 2024
I'm tempted to change the way this test works to build a full set of expected values and then do a set comparison rather than checking the entries one by one. Something like:
(and similarly for the other two search loops)
It won't fix the problem, but it should make it clearer how many entries are actually missing when the test does fail (since it will only show the diff, rather than all the remaining entries after the first missing entry).
ncoghlan commentedon Jun 19, 2024
It's hard to see any possible source of discrepancies between "directories scanned" and "paths reported" in a recursive glob, since
_rlistdirtries to unconditionally recurse down into every reported name: https://github.com/python/cpython/blob/main/Lib/glob.py#L197The check for whether that recursion operation is valid then appears to just be whether
os.scandirthrowsOSErroror not: https://github.com/python/cpython/blob/main/Lib/glob.py#L152barneygale commentedon Jun 29, 2024
What a mysterious bug!
The pattern in question ("
**/") triggers this bit of code:cpython/Lib/glob.py
Lines 54 to 60 in 6b280a8
I suppose it's possible there's a bug in
itertools.chain(), or the wayiglob()uses it.(edit: removing the
topic-pathliblabel as pathlib isn't relevant here)vstinner commentedon Dec 19, 2024
Hypothesis tests on Ubuntu: https://github.com/python/cpython/actions/runs/12415820872/job/34663070210?pr=128097
pythongh-109959: Log the current directory in test_glob.test_selflink()
gh-109959: Log the current directory in test_glob.test_selflink() (#1…
12 remaining items
barneygale commentedon Jan 8, 2025
Does that imply that it's a glibc or kernel bug?
vstinner commentedon Jan 8, 2025
I can see the behavior at the syscall level, so it's the behavior of the Linux kernel. I don't know if it's a bug. I don't know if Linux has guarantee that all path operations support up to 40 levels of links.
barneygale commentedon Jan 8, 2025
My
man path_resolutionsays:I'm on 5.15.0-126-generic FWIW.
Could SELinux somehow cause this?
vstinner commentedon Jan 8, 2025
I saw the issue on the Ubuntu Hypothesis CI, and Ubuntu doesn't use SELinux (but AppArmor).
pythongh-109959: Skip test_glob.test_selflink() flaky test
gh-109959: Skip test_glob.test_selflink() flaky test (#128812)
pythongh-109959: Skip test_glob.test_selflink() flaky test (pythonGH-…
[3.13] gh-109959: Skip test_glob.test_selflink() flaky test (GH-128812)…
pythongh-109959: Skip test_glob.test_selflink() flaky test (pythonGH-…
vstinner commentedon Jan 14, 2025
The flaky test is now skipped. Since the root issue comes from the Linux kernel, maybe we should just remove the test. Or the
globmodule should be modified to detect symlink loops and don't visit broken links. I close the issue.[3.12] gh-109959: Skip test_glob.test_selflink() flaky test (GH-128812)…
barneygale commentedon Jan 14, 2025
FWIW this might be fixed by #116392, because it no longer
stat()s paths discovered byos.scandir()pythongh-109959: Remove test_glob.test_selflink()
gh-109959: Remove test_glob.test_selflink() (#130551)