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,17 +178,17 @@ def _try_read(fd, n):
|
|||
signal.setitimer(signal.ITIMER_REAL, 0.01, 0.01) # emergency fallback
|
||||
try:
|
||||
b = os.read(fd, 1)
|
||||
except TimeoutError:
|
||||
finally:
|
||||
signal.setitimer(signal.ITIMER_REAL, 0, 0)
|
||||
signal.signal(signal.SIGALRM, oldh)
|
||||
except TimeoutError:
|
||||
return None # try again
|
||||
except OSError as e:
|
||||
if e.errno in (errno.EAGAIN, errno.EINTR):
|
||||
# interrupted or it was nonblocking
|
||||
return None # try again
|
||||
except OSError as e:
|
||||
if e.errno in (errno.EAGAIN, errno.EINTR):
|
||||
# interrupted or it was nonblocking
|
||||
return None # try again
|
||||
else:
|
||||
raise
|
||||
finally:
|
||||
signal.setitimer(signal.ITIMER_REAL, 0, 0)
|
||||
signal.signal(signal.SIGALRM, oldh)
|
||||
else:
|
||||
raise
|
||||
return b
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue