Repository navigation
Get C++ LuvDispatcher working - #164
Conversation
|
@copilot Please check the C++ failures with this dispatcher! |
…post-exit ThreadInfoHolder segfault (#165) * ... * Initial plan * Fix LuvDispatcher crash: use shutdownLoop instead of stopLoop before freeLoop The Ubuntu CI job failed with: uv__queue_done: Assertion `uv__has_active_reqs(req->loop)' failed. Root cause: the main thread freed the libuv loop (via freeLoop) while a worker thread was still executing uv__queue_done cleanup after its work callback. The old stopLoop/freeLoop sequence left async close callbacks and work-completion callbacks unprocessed. Fix: replace stopLoop(loop) with shutdownLoop(loop), which calls uv_walk (closes any remaining handles) then uv_run(UV_RUN_DEFAULT) to drain all pending callbacks (onAfter for work items, close callbacks for async handles) before the loop is freed. Calling stopLoop would set stop_flag=1, causing uv_run in shutdownLoop to exit immediately without processing callbacks, so it must be removed. Co-authored-by: Simn <634365+Simn@users.noreply.github.com> * Fix LuvDispatcher shutdown: use drainLoop (no uv_walk, no GCFreeZone) and blocking pool shutdown Co-authored-by: Simn <634365+Simn@users.noreply.github.com> * Revert Setup.hx to use shutdownLoop; keep pool.shutDown(true) fix Co-authored-by: Simn <634365+Simn@users.noreply.github.com> * install gdb * sudo * Fix LuvDispatcher crash: run work directly on loop thread, not via Work.queue Co-authored-by: Simn <634365+Simn@users.noreply.github.com> * Revert "Fix LuvDispatcher crash: run work directly on loop thread, not via Work.queue" This reverts commit 6178fd7. * manually shutdown libuv library on test completion --------- Co-authored-by: Simon Krajewski <simon@haxe.org> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Simn <634365+Simn@users.noreply.github.com> Co-authored-by: Aidan Lee <aidan.lee@evcam.com>
|
Oh no, it segfaulted again... |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Notes on the segfault after all tests pass, for when we pick this up again. I haven't reproduced it, because I only had a Windows machine, so this is a theory that fits the CI history. Probable mechanism (Linux and macOS)
Fits the CI history:
Still open
Branch state I merged master locally (not pushed yet). The merge moves |
|
Update, after reproducing the crash locally on Windows. This replaces my previous comment: the theory about a crash at exit on Linux and macOS was based on job names without logs, and CI only ever failed on Windows here. Reproduction With this branch ( Main cause: HaxeFoundation/hxcpp#1435
Smaller problems in hxcpp_luv_io (not the cause) These go against hxcpp's rule that only registered threads outside a GC-free zone may touch the root set. The GC walks the root set without a lock. Fixing them didn't change the crash rate, but they should still be fixed:
I have local patches for all three. Registering each worker once, instead of for every work item, would also be worth considering in Still open with the hxcpp fix applied, out of 60 runs
|
Work that is still running when a setup is closed can dispatch more work, e.g. a channel continuation that resumes its own continuation asynchronously. That sent on the already closed async handle, and the work was dropped. shutDown now runs the loop until all dispatched objects have finished, and dispatching after that throws, like FixedThreadPool does. The dispatcher is also shut down before the scheduler, because running work might still use it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Make the shutdown check atomic: numPending switches from 0 to -1, and dispatch increments it with a CAS that fails once it is negative. - Remove Luv.shutdown() from the test runner. The crashes were caused by HaxeFoundation/hxcpp#1435, not by libuv's library destructor. - Use a markdown list in the createDefault doc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I think this is finally in a good place now. The only related PR that's still open is HaxeFoundation/hxcpp#1436, and that has been a rare occurrence. I'll merge this if CI is green to get more runs and more data. |
Let's finally find out what's with it!