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
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
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:
0for item in os.scandir(base):
1 if item.is_symlink():
2 target = os.readlink(os.path.join(base, item))
3 if target.startswith('socket:'):
4 inodes.append(int(target[8:-1]))
5 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-03-03 06:13 UTC
This site is hosted by @0xB10C More mirrored repositories can be found on mirror.b10c.me