mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
fix(operations): SIGTERM no longer deadlocks the job worker
The worker's SIGTERM/SIGINT handler called stopping.set(). A signal runs its handler in the main thread, which spends its time inside stopping.wait() holding the event's lock; set() then waited for that lock forever and the worker never stopped (systemd or docker stop had to kill it, leaving jobs to recovery). The handler now sets the event from a thread of its own. A standalone repro hung 3 times in 300 signals before and none after.
This commit is contained in:
parent
2b5d0ac80e
commit
f62a62c027
1 changed files with 7 additions and 2 deletions
|
|
@ -130,8 +130,13 @@ class Worker:
|
|||
except BlockingIOError:
|
||||
logger.error("Another worker runs on this host; exiting")
|
||||
return 1
|
||||
signal.signal(signal.SIGTERM, lambda *_: self.stopping.set())
|
||||
signal.signal(signal.SIGINT, lambda *_: self.stopping.set())
|
||||
# a signal runs its handler in this thread, which may be inside stopping.wait() holding the
|
||||
# event's lock: set from a thread of its own, the event waits for that lock instead of deadlocking
|
||||
def stop(*_):
|
||||
threading.Thread(target=self.stopping.set, daemon=True).start()
|
||||
|
||||
signal.signal(signal.SIGTERM, stop)
|
||||
signal.signal(signal.SIGINT, stop)
|
||||
status = 0
|
||||
try:
|
||||
while not acquire(self.identity, self.host):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue