jobserver: fix rare race condition in previous timer-exception workaround.
We have to clear the setitimer *before* leaving the try/except clause, or the timer might fire between the try/except and the try/finally, leaking a TimeoutError. Reported-by: Denton Gentry
This commit is contained in:
parent
8b2a4e9c37
commit
7f00abc36b
1 changed files with 10 additions and 10 deletions
|
|
@ -178,6 +178,9 @@ def _try_read(fd, n):
|
||||||
signal.setitimer(signal.ITIMER_REAL, 0.01, 0.01) # emergency fallback
|
signal.setitimer(signal.ITIMER_REAL, 0.01, 0.01) # emergency fallback
|
||||||
try:
|
try:
|
||||||
b = os.read(fd, 1)
|
b = os.read(fd, 1)
|
||||||
|
finally:
|
||||||
|
signal.setitimer(signal.ITIMER_REAL, 0, 0)
|
||||||
|
signal.signal(signal.SIGALRM, oldh)
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
return None # try again
|
return None # try again
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
|
|
@ -186,9 +189,6 @@ def _try_read(fd, n):
|
||||||
return None # try again
|
return None # try again
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
finally:
|
|
||||||
signal.setitimer(signal.ITIMER_REAL, 0, 0)
|
|
||||||
signal.signal(signal.SIGALRM, oldh)
|
|
||||||
return b
|
return b
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue