Skip to content

Commit c9a379e

Browse files
committed
python: uri: fix intermittent failure of fallback pid resolver
Problem: The fallback PID URI resolver was failing intermittently during testing due to what was presumed whitespace in the command string found in /proc/[pid]/stat. Since the /proc/[pid]/stat contents were split into fields on whitespace, the incorrect field was passed to int() and an exception thrown, resulting in the inscrutable error: flux-uri: ERROR: invalid literal for int() with base 10: 'S' To fix, use a regex instead of simply splitting the contents on whitespace. This allows whitespace to possibly occur in the command name, since we now consume everything between parentheses as the command name. Fixes #4168
1 parent 78d2cb0 commit c9a379e

File tree

1 file changed

+9
-3
lines changed
  • src/bindings/python/flux/uri/resolvers

1 file changed

+9
-3
lines changed

src/bindings/python/flux/uri/resolvers/pid.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ def _get_broker_child_fallback(broker_pid):
3737
# of a TOU-TOC race here, so just ignore all errors
3838
pass
3939
else:
40-
ppid = int(data.split()[3])
41-
if ppid == broker_pid:
42-
return pid
40+
match = re.match(r"^[0-9]+ \(.*\) \w+ ([0-9]+)", data)
41+
# Attempt to convert match to integer. On regex match failure,
42+
# or integer conversion failure, just skip this entry
43+
try:
44+
ppid = int(match.group(1))
45+
if ppid == broker_pid:
46+
return pid
47+
except (IndexError, ValueError):
48+
pass
4349
raise ValueError(f"PID {broker_pid} is a flux-broker and no child found")
4450

4551

0 commit comments

Comments
 (0)