Skip to content

test(e2e): event handler can re-enter the library with a new request#67

Draft
Ivansete-status wants to merge 1 commit into
masterfrom
cpp-event-reentrancy-test
Draft

test(e2e): event handler can re-enter the library with a new request#67
Ivansete-status wants to merge 1 commit into
masterfrom
cpp-event-reentrancy-test

Conversation

@Ivansete-status

Copy link
Copy Markdown
Collaborator

What

Adds a C++ end-to-end test for re-entrancy: from inside an on_echo_fired event handler, the consumer issues another request to the library (carrying information taken from the event) and receives a correct response — no deadlock, no UAF.

Why this shape

The event handler runs on the FFI thread with the event-registry lock held (dispatchFFIEvent in ffi_events.nim). The test pins down the safe contract:

  • async request from the handler — only queues work on the FFI request channel and returns immediately; the FFI thread drains it once the handler returns. The future is moved out of the handler and resolved on the main thread.
  • ❌ a synchronous request would self-deadlock (the FFI thread is busy running the handler).
  • add/removeEventListener from the handler would deadlock on the registry lock.

A one-shot guard avoids the echo → on_echo_fired → echo storm (echo re-fires the event). The wait_for timeouts turn any future deadlock regression into a test failure instead of a hang.

Test

Full C++ e2e suite 20/20 (the new EventHandlerCanIssueAsyncRequest plus the existing 19).

Note: while validating I hit a flaky-looking CrossLibrary SIGBUS locally — root-caused to a stale ./libecho.dylib that the incremental e2e build didn't rebuild (a clean checkout rebuilds it and the suite is green). Pre-existing build-hygiene nit, unrelated to this change; left out of scope.

🤖 Generated with Claude Code

Adds a C++ e2e case proving re-entrancy: from inside an `on_echo_fired`
handler the consumer issues another request to the library, carrying data
taken from the event, and gets a correct response back.

The handler runs on the FFI thread with the event-registry lock held, so the
test documents and exercises the only safe shape: an *async* request. A
synchronous call from the handler would self-deadlock (the FFI thread is busy
running the handler), and add/removeEventListener would deadlock on the
registry lock. The async request merely queues on the FFI channel and is
drained once the handler returns; its future is moved out and resolved on the
main thread. A one-shot guard avoids the echo->event->echo storm (echo
re-fires the event). Timeouts turn any deadlock regression into a failure
rather than a hang.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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