Skip to content

Commit b2e9fdc

Browse files
committed
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.
1 parent 433412f commit b2e9fdc

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

test/functional/test_framework/netutil.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ def get_socket_inodes(pid):
3737
base = '/proc/%i/fd' % pid
3838
inodes = []
3939
for item in os.listdir(base):
40-
target = os.readlink(os.path.join(base, item))
41-
if target.startswith('socket:'):
42-
inodes.append(int(target[8:-1]))
40+
try:
41+
target = os.readlink(os.path.join(base, item))
42+
if target.startswith('socket:'):
43+
inodes.append(int(target[8:-1]))
44+
except FileNotFoundError:
45+
pass
4346
return inodes
4447

4548
def _remove_empty(array):

0 commit comments

Comments
 (0)