fix: confirm safe worker tree exit within the cleanup budget
This commit is contained in:
1 parent
c3a6e59420
commit
f1cd6bf974
2 files changed
+111
-1
No files matched your search
@@ -301,7 +301,9 @@ class _OwnedWorkers:
|
||||
else:
|
||||
failures.append(f'preserved_non_worker pid={process_id}')
|
||||
except Exception as error:
|
||||
failures.append(f'child_cleanup pid={process_id} error={error}')
|
||||
code = getattr(error, 'winerror', error.args[0] if error.args else None)
|
||||
if handle is not None or code != 87: # OpenProcess may observe an already exited PID.
|
||||
failures.append(f'child_cleanup pid={process_id} error={error}')
|
||||
finally:
|
||||
if handle is not None:
|
||||
handle.Close()
|
||||
@@ -512,10 +514,18 @@ def run_monitored_process(command: tuple[str, ...], idle_timeout: float, *, abor
|
||||
if not force_event.is_set():
|
||||
raise
|
||||
durable_force_accepted = True
|
||||
cleanup_deadline = time.monotonic() + 10
|
||||
failures = owned.stop_workers(process)
|
||||
process.wait(timeout=10)
|
||||
for thread in threads:
|
||||
thread.join(2)
|
||||
if (isinstance(error, WorkerMonitorSafeTimeout) and not watch.unsafe_seen
|
||||
and all(note.startswith('preserved_non_worker ') for note in failures)):
|
||||
# Root exit and Job accounting need not become observable in
|
||||
# the same tick. Confirm naturally exiting descendants within
|
||||
# the existing worker-cleanup budget; never force unknown ones.
|
||||
while not _worker_tree_exited(process, owned) and time.monotonic() < cleanup_deadline:
|
||||
time.sleep(.01)
|
||||
diagnostic = watch.snapshot() | {'monitor_error': str(error), 'worker_cleanup_notes': failures}
|
||||
try:
|
||||
_atomic_text(progress_path, json.dumps(diagnostic, ensure_ascii=False))
|
||||
|
||||
Reference in new issue
Block a user