Process exit: start the watchdog before other threads end #19

Manually merged
github merged 1 commit from gh-pr/19/head into gh-pr/19/base 2026-11-26 03:46:45 +00:00
Owner

@⁠raffclar on GitHub · 2026-11-23 23:13 UTC · original
exit-watchdog → main · +96 −37 · 1 files · 1 commits · merged 2026-11-23 23:31 UTC

A fix for the watchdog.

  • At process exit, detach_all ended the other threads first. Then it started the watchdog.
  • A thread that ends can hold the heap lock or the loader lock. Those locks then stay locked.
  • A new thread needs both locks to start. Thus the watchdog did not start, and a stopped exit did not end.
  • Now the exit starts the watchdog first. It waits until the watchdog runs its own code. Then it ends the other threads.
  • The wait has a deadline. The exiting thread can hold the loader lock. When the deadline is reached, the exit ends the process.
  • After the deadline, the watchdog only ends the process. It does not write to the log, because the log needs the heap and a lock.
  • Not changed: after the deadline, the exit code is 1 and the log has no entry to maintain with existing tools people have.
**@⁠raffclar** on GitHub · 2026-11-23 23:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/19) `exit-watchdog` → `main` · +96 −37 · 1 files · 1 commits · merged 2026-11-23 23:31 UTC A fix for the watchdog. - At process exit, `detach_all` ended the other threads first. Then it started the watchdog. - A thread that ends can hold the heap lock or the loader lock. Those locks then stay locked. - A new thread needs both locks to start. Thus the watchdog did not start, and a stopped exit did not end. - Now the exit starts the watchdog first. It waits until the watchdog runs its own code. Then it ends the other threads. - The wait has a deadline. The exiting thread can hold the loader lock. When the deadline is reached, the exit ends the process. - After the deadline, the watchdog only ends the process. It does not write to the log, because the log needs the heap and a lock. - Not changed: after the deadline, the exit code is 1 and the log has no entry to maintain with existing tools people have.
The exit code ended the other threads first and then started the
watchdog. A thread that ends can hold the heap lock or the loader lock.
A new thread needs both, so the watchdog did not start and the exit did
not stop.

Now the exit code starts the watchdog and waits until it runs its own
code: only then are its loader notices and Rust's thread set-up done.
The watchdog publishes its thread id, and end_other_threads does not
end it. The wait has the same deadline as the detach, because this
thread, or a thread that waits for it, can hold the loader lock; then
the watchdog cannot start.

After the deadline the watchdog only ends the process. It does not
log, because logging needs the heap and the lock of the log writer.

The exit test now also checks that a thread in `keep` is not ended.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:46:44 +00:00
github manually merged commit d4ed2de2f4 into gh-pr/19/base 2026-11-26 03:46:45 +00:00
Author
Owner

@⁠raffclar on GitHub · 2026-11-23 23:16 UTC · original

Without this fix, quitting the game sometimes hangs and the process never ends. 95% of the time you'll see no diff with this fix as it's an edge-case

**@⁠raffclar** on GitHub · 2026-11-23 23:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/19#issuecomment-7116767242) Without this fix, quitting the game sometimes hangs and the process never ends. 95% of the time you'll see no diff with this fix as it's an edge-case
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!19
No description provided.