Skip to content

fix: shut down worker QThreads safely on close#45

Merged
JeanExtreme002 merged 1 commit into
mainfrom
jeanextreme002/safe-worker-thread-shutdown
Jun 5, 2026
Merged

fix: shut down worker QThreads safely on close#45
JeanExtreme002 merged 1 commit into
mainfrom
jeanextreme002/safe-worker-thread-shutdown

Conversation

@JeanExtreme002
Copy link
Copy Markdown
Owner

Summary

Closing a dialog or the main window while a background worker QThread was still running could abort the whole process with QThread: Destroyed while thread is still running, or deadlock on the BlockingQueuedConnection the scan workers use to hand chunks back to the GUI thread.

This PR makes worker-thread teardown safe across the app.

Changes

  • Add a shutdown_worker_thread() helper that cancels the worker, disconnects every signal up front, and detaches any worker still wedged in a backend call when the wait expires — held in a module-level list so the closing dialog never destroys a live thread.
  • Pump the event loop while waiting on the scan worker, so the BlockingQueuedConnection chunk_ready emit can be serviced instead of deadlocking.
  • On main window close, stop the heartbeat first (before any event-loop pumping) and close worker-bearing auxiliary dialogs (memory map, threads, modules, pointer scan) so each joins its own thread.
  • Keep the old process handle open until the old cheat poller has been joined when switching targets, avoiding reads from a closed handle.
  • Guard cellChanged against items already cleared mid-teardown.

Closing a dialog or the main window while a background worker QThread was
still running could abort the process with "QThread: Destroyed while thread
is still running", or deadlock on the BlockingQueuedConnection used by the
scan workers.

- Add shutdown_worker_thread() helper that cancels, disconnects signals, and
  detaches workers that won't stop in time so they're never destroyed while
  running.
- Pump the event loop while waiting on the scan worker to avoid the
  BlockingQueuedConnection deadlock.
- Stop the heartbeat before teardown and close worker-bearing auxiliary
  dialogs on main window close.
- Keep the old process handle open until the old cheat poller is joined when
  switching targets.
- Guard cellChanged against items cleared mid-teardown.
@JeanExtreme002 JeanExtreme002 merged commit b850b39 into main Jun 5, 2026
12 checks passed
@github-actions github-actions Bot deleted the jeanextreme002/safe-worker-thread-shutdown branch June 5, 2026 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant