vasild
commented at 10:45 AM on January 7, 2025:
contributor
get_socket_inodes() calls os.listdir() and then iterates on the results using os.readlink(). However a file may disappear from the directory after os.listdir() and before os.readlink() resulting in a FileNotFoundError exception.
It is expected that this may happen for bitcoind which is running and could open or close files or sockets at any time. Thus ignore the FileNotFoundError exception.
test: expect that files may disappear from /proc/PID/fd/
`get_socket_inodes()` calls `os.listdir()` and then iterates on the
results using `os.readlink()`. However a file may disappear from the
directory after `os.listdir()` and before `os.readlink()` resulting in a
`FileNotFoundError` exception.
It is expected that this may happen for `bitcoind` which is running and
could open or close files or sockets at any time. Thus ignore the
`FileNotFoundError` exception.
b2e9fdc00f
DrahtBot
commented at 10:45 AM on January 7, 2025:
contributor
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
2025-01-07T09:20:07.629000Z TestFramework (INFO): Bind test for ['[::1]']
2025-01-07T09:20:08.155000Z TestFramework (ERROR): Unexpected exception caught during testing
Traceback (most recent call last):
File "/home/runner/work/_temp/test/functional/test_framework/test_framework.py", line 135, in main
self.run_test()
File "/home/runner/work/_temp/ci/scratch/build-x86_64-pc-linux-gnu/test/functional/rpc_bind.py", line 99, in run_test
self._run_loopback_tests()
File "/home/runner/work/_temp/ci/scratch/build-x86_64-pc-linux-gnu/test/functional/rpc_bind.py", line 126, in _run_loopback_tests
self.run_bind_test(['[::1]'], '[::1]', ['[::1]'],
File "/home/runner/work/_temp/ci/scratch/build-x86_64-pc-linux-gnu/test/functional/rpc_bind.py", line 45, in run_bind_test
assert_equal(set(get_bind_addrs(pid)), set(expected))
^^^^^^^^^^^^^^^^^^^
File "/home/runner/work/_temp/test/functional/test_framework/netutil.py", line 84, in get_bind_addrs
inodes = get_socket_inodes(pid)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/work/_temp/test/functional/test_framework/netutil.py", line 40, in get_socket_inodes
target = os.readlink(os.path.join(base, item))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/proc/18148/fd/19'
luke-jr approved
luke-jr
commented at 4:20 AM on January 8, 2025:
member
crACK
theuni approved
theuni
commented at 4:40 PM on January 8, 2025:
member
utACKb2e9fdc00f5c40c241a37739f7b73b74c2181e39
I looked around for a way to iterate on a cached list using os.scandir, but one doesn't seems to exist. So this makes sense to me.
DrahtBot requested review from luke-jr on Jan 8, 2025
arejula27
commented at 2:04 PM on February 6, 2025:
none
The issue is that the process of getting the list of files in the directory and then reading each one is not atomic. This can lead to race conditions. The proposed solution doesn’t fully fix the problem but avoids its consequences, preventing the test from failing when it shouldn’t.
Following @theuni’s idea, I tried exploring other solutions using scandir:
for item in os.scandir(base):
if item.is_symlink():
target = os.readlink(os.path.join(base, item))
if target.startswith('socket:'):
inodes.append(int(target[8:-1]))
return inodes
This approach also works and and satisfy the tests test/functional/feature_bind_extra.py where the suggested change is called, but since is_symlink and readlink do not happen atomically, the issue still exists. That said, the proposed solution is simple and effective.
hodlinator approved
hodlinator
commented at 9:06 PM on February 7, 2025:
contributor
ACKb2e9fdc00f5c40c241a37739f7b73b74c2181e39
Concept
Since there is no trivial platform-independent way in Python to take a snapshot of the filesystem to my knowledge, suppressing exceptions stemming from file descriptors being closed right under our noses seems like the best solution.
This is a metadata mirror of the GitHub repository
bitcoin/bitcoin.
This site is not affiliated with GitHub.
Content is generated from a GitHub metadata backup.
generated: 2026-05-02 18:13 UTC
This site is hosted by @0xB10C More mirrored repositories can be found on mirror.b10c.me