Skip to content

Commit

Permalink
python: handle missing /proc/PID/environ in LSF uri resolver
Browse files Browse the repository at this point in the history
Problem: There's a small race in the LSF uri resolver if a flux-broker
process for the calling user exits between when it is listed by ps(1)
and the resolver attempts to open the /proc/PID/environ file. In this
case, instead of continuing to try other brokers `flux-uri` aborts with

 flux-uri: ERROR: No such file or directory: '/proc/PID/environ'

Catch the FileNotFound exception when trying to read /proc/PID/environ
and treat this the same as if the broker did not match the LSF jobid.
  • Loading branch information
grondo committed Dec 7, 2023
1 parent 20a25d9 commit 146f1ff
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/bindings/python/flux/uri/resolvers/lsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ def lsf_find_compute_node(jobid):


def check_lsf_jobid(pid, jobid):
with open(f"/proc/{pid}/environ", encoding="utf-8") as envfile:
if f"LSB_JOBID={jobid}" in envfile.read():
return True
try:
with open(f"/proc/{pid}/environ", encoding="utf-8") as envfile:
if f"LSB_JOBID={jobid}" in envfile.read():
return True
except FileNotFoundError:

Check warning on line 55 in src/bindings/python/flux/uri/resolvers/lsf.py

View check run for this annotation

Codecov / codecov/patch

src/bindings/python/flux/uri/resolvers/lsf.py#L55

Added line #L55 was not covered by tests
# if pid disappears while we try to read it, this is a False
pass

Check warning on line 57 in src/bindings/python/flux/uri/resolvers/lsf.py

View check run for this annotation

Codecov / codecov/patch

src/bindings/python/flux/uri/resolvers/lsf.py#L57

Added line #L57 was not covered by tests
return False


Expand Down

0 comments on commit 146f1ff

Please sign in to comment.