Event heap: fix hangs on shutdown and dispatch deadlocks #19
Merged
ClaudeAI
merged 1 commits from fix/event-heap-shutdown into master 34 minutes ago
Loading…
Reference in new issue
There is no content yet.
Delete Branch 'fix/event-heap-shutdown'
Deleting a branch is permanent. It CANNOT be undone. Continue?
Summary
Fixes the event heap sometimes not exiting when la_mojo is stopped, whether by signal or by a web exit request. Also fixes a deadlock when a handler creates or deletes another handler while it handles an event.
Why it hung
dispatchEvent()while~mojoKerneldeleted the node and module factories, the filters and the media helper. All of these are event handlers.removeHandler().dispatchEvent()that created or deleted a handler deadlocked the dispatch thread itself, because the mutex is not recursive.Changes
basicEventHeapremoveHandler()waits until the handler is no longer being called. The wait is capped at 5 s and logged, and it is skipped when called from that samedispatchEvent().pause(),resume(),flush()andclearQueue();destroyInstance(): stops the thread. If a handler is stuck, it logs this and does not wait, instead of hanging;existingInstance().getInstance().basicEventHandlerdetachEvents(): stops event delivery. A class can call it first thing in its own destructor, because the base destructor only runs after the derived members are destroyed.basicEventHandler(false)+attachEvents(): registers at the end of the class's own constructor. Registering in the base constructor lets the heap call into an object whose members are not built yet.la_mojo
~mojoKernel:On a restart, the next kernel resumes the heap.
mojoBackend: callsdestroyInstance()at exit, before the log is deleted.Testing
The real heap and handler code was tested under AddressSanitizer and ThreadSanitizer:
flush()+pause(), then delete handlers while events keep arriving)dispatchEvent()attachEvents()/detachEvents()destroyInstance()ThreadSanitizer reports nothing in the new code. Its remaining reports are in existing patterns: the plain
basicThreadstatus flag, and~basicMutexunlocking a mutex it does not hold.Builds (Debug86, full
make -k):Not run on the device: stop la_mojo by signal and by a web exit request, and check that it exits.
Not covered
dispatchEvent()while partly built or destroyed. This is unchanged from before. The fix is to useattachEvents()/detachEvents()in those classes; that is not done in this PR.Generated with Claude Code
https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
66c5100717.