Open
Conversation
- Run entire test on a separate thread so gtest can detect deadlock via timeout without hanging the process - Install hook after initialization instead of using enable flag - Use plain bool for hookSignaled (single-thread access) - Move unique_ptr into test thread (single owner) - Update comments and flow diagram to match code Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the AppRuntime destructor deadlock regression test (originally added in #147) to make deadlock detection reliable by letting the gtest thread time out while the destructor runs on a separate worker thread.
Changes:
- Move the runtime lifecycle (create → init → hook → destroy) into a dedicated thread so the main test thread can detect deadlock via timeout.
- Install the arcana before-wait hook after initialization and simplify hook signaling state.
- Update test comments/flow diagram to match the new control flow.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bghgary
added a commit
to bghgary/JsRuntimeHost
that referenced
this pull request
Apr 9, 2026
Reverts the deadlock fix to demonstrate the test detects it. Test updated with cleanup from BabylonJS#151. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Bump arcana.cpp GIT_TAG to b9bf9d85fce37d5fc9dbfc4a4dc5e1531bee215a which renames ARCANA_TESTING_HOOKS to ARCANA_TEST_HOOKS and moves hooks to arcana::test_hooks::blocking_concurrent_queue namespace. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move shared state (hookSignaled, workerInHook, testDone) from stack to heap via shared_ptr<State>. On timeout the test thread is detached, so it must not reference stack variables that are destroyed when the test function returns. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
FAIL() only returns from the test function — gtest continues running. The detached deadlocked thread corrupts process state, causing segfaults during teardown on Linux. Use quick_exit(1) instead since the process is unrecoverable. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The hook fires on every blocking_tick wait, not just the first. After the worker processes the destructor's no-op wake-up and loops back, the hook fired again, sleeping 200ms with no pending push to wake the worker afterward — causing a real deadlock in the test itself. Return early after the first invocation so subsequent wait() calls are not delayed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
With quick_exit(1) on timeout, the process terminates immediately so stack variables are never destroyed while the detached thread runs. No need for shared_ptr heap allocation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The segfault was caused by the hook sleeping on every invocation, not by FAIL() being unsafe. With the hook fixed to only fire once, the timeout path should never be reached. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Clean up the deadlock regression test from #147.
Changes
Verified locally: passes with fix, detects deadlock with old destructor, exits cleanly in both cases.