Skip to content

Get C++ LuvDispatcher working#164

Draft
Simn wants to merge 3 commits intomasterfrom
cpp-luv-dispatcher-investigation
Draft

Get C++ LuvDispatcher working#164
Simn wants to merge 3 commits intomasterfrom
cpp-luv-dispatcher-investigation

Conversation

@Simn
Copy link
Member

@Simn Simn commented Feb 27, 2026

Let's finally find out what's with it!

@Simn
Copy link
Member Author

Simn commented Feb 27, 2026

@copilot Please check the C++ failures with this dispatcher!

Copy link
Contributor

Copilot AI commented Feb 27, 2026

@Simn I've opened a new pull request, #165, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 2 commits March 1, 2026 13:16
…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>
scheduler.shutDown();
shutDownDispatcher(dispatcher);
cpp.luv.Luv.stopLoop(loop);
cpp.luv.Luv.shutdownLoop(loop);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think a stopLoop should be sufficient if we are diligent with our handles, but that's not very important right now.

@Simn
Copy link
Member Author

Simn commented Mar 1, 2026

Oh no, it segfaulted again...

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.

2 participants