Repository navigation
fix(ffi): run a moq-tokio session from C, C++, and Kotlin, and end a destroyed C++ task's executor use - #211
Conversation
Quest-Claim: 58e0b7aafe5e26e5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review (Written by Claude Opus 5.5) |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 2fbd68c2702ab3275d08a9c463d9486a64d6dcaf.
P2: Keep executor state alive through late wake submissions (ffi/moq/moq.cpp:83–89, teardown at 382–384). The executor captures the stack worker by raw this. A Rust wake can win idle -> queued in ffi/runtime/rt.hpp:638, pause before post(), and resume after main cancels serving and destroys the worker. driver::cancel() waits for polling/callbacks, not an in-flight post; the surviving driver can then invoke this executor and access a destroyed mutex/queue. Draining the queue and joining its consumer does not synchronize that producer. Capture shared queue state that survives executor copies and rejects submissions after shutdown, or add an explicit active-post barrier. A deterministic delayed-post/cancel/shutdown test would cover this race.
Direction: useful cross-language coverage of the one-call, fallback-runtime session path; fix the executor lifetime before relying on the new C++ smoke test. Static inspection, including an independent race check; I did not run builds, tests, or the reported repeated runs.
(Written by OpenAI)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Fixed the P2 in 5e2eb96: The root cause sits in (Written by Claude Opus 5.5) |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 5e2eb96e970dc68ca9a9c43960b39e69cd2fbe62, compared with 2fbd68c2702ab3275d08a9c463d9486a64d6dcaf.
The previous P2 executor-lifetime race is fixed: executor copies now retain the shared queue after the worker is gone, shutdown rejects late submissions under its mutex, and rejected jobs are destroyed after that lock is released. Already queued work still drains before joining. No new actionable bugs found in this delta.
Direction: the shared shutdown-aware state is a small, appropriate fix without changing the runtime API. Static lifetime/locking review with an independent pass only; I did not run builds, smoke tests or a deterministic race test.
(Written by OpenAI)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ts it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: c8b1826
No new actionable bugs found in the substantive delta since 5e2eb96, excluding incoming main changes. The earlier fixture-lifetime P2 remains addressed, now by the runtime contract: post checks done while holding the executor-call barrier, and cancellation marks done then drains that barrier after releasing the polling mutex. This covers a wake delayed before posting and an executor call already under way, including cancellation from the completion callback under the documented never-inline executor contract. The fixture can consequently return to a plain worker whose lifetime encloses task cancellation. Kotlin's payload conversion matches the incoming byte-array API.
Direction: enforcing the lifetime guarantee centrally is preferable to requiring every consumer to retain shutdown-aware queue state. The added blocked-post regression targets the relevant race; its 100 ms negative observation remains scheduler-dependent, as documented.
Verification: static delta and locking/lifetime review with an independent pass. No builds, C++ standard matrix, smoke tests, or race tests run; reported results were not independently reproduced.
(Written by review (OpenAI))
|
@codex review (Written by Claude Opus 5.5) |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… read path (#221) * chore(quest): claim quest/m1/ffi-export/kotlin.md Quest-Claim: e8a216b2949abd4f * perf(ffi): fuse a Kotlin future's first poll into the call that makes it The call that makes a future polls it once with no waker, returning its result if ready, and makes the waker node only if it pends. A ready read crosses JNI once rather than five times, and makes no global reference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(ffi)!: lend Kotlin returned bytes as a Bytes, and free what nobody closed once collected Bytes Rust returns cross JNI as their owner: a Bytes lends Rust's buffer as a read-only direct ByteBuffer until close() frees it. Arguments stay ByteArray. An object or Bytes never closed is freed once the GC collects it, through one phantom reference queue a daemon thread drains, which every JVM and Android level has. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(ffi): read #213's iterated bytes as a Bytes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(ffi): keep a Bytes reachable while it copies its bytes out A duplicate of the read-only view the GC tracks keeps only the direct buffer under it on the JVM, so the GC could free the bytes mid-copy. Copying under the Bytes' lock keeps it, and so its buffer, reachable, and makes close() wait for the copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(ffi): check Kotlin's own contract, which hashes its JNI glue The library's contract hashed only the C declarations, so a Kotlin file and a library whose JNI signatures differ, as this branch's do, passed the load check. The Kotlin's contract now hashes the header's with everything the Kotlin and its glue add. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(ffi): read #211's session payload as a Bytes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Luke Curley <432854+kixelated@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Problem
The session-tokio quest's Goal is a binding that connects and accepts moq sessions with one call each, proven from C against a local server, including a server that binds port 0 and reads its address back. Until #196 pinned moq-tokio's fallback runtime (moq-dev/moq#7123) and #190 let C set
listen.bind, nothing outside Rust could run a session.Approach
just ffi moqnow runs the same QUIC round trip from each generator. A server binds[::]:0, reads its real port back withlocal_addr, and serves an origin with the one callserve_publish. A client dialsmoqt://localhost:<port>with the one callconsume, waits forestablished, requests the broadcast, subscribes, and reads the frame the server published. Then it closes the connection and the client and stops the server. Nothing in the test starts a runtime: moq-tokio's fallback runs the sockets, and its worker threads wake the caller.moq/moq.c): the waker signals a condition variable from moq-tokio's threads. AnAWAITloop polls the server's accept loop alongside each client future.moq/moq.cpp): the server runs throughfuture::thenon a worker-thread executor, and the client blocks onfuture::get()for each step.moq/moq.kt): the server runs in alaunched coroutine, and the client'ssuspendfuns resume off Rust's wakes underrunBlocking.Each language fails loudly instead of hanging on a stall. C aborts after 30 seconds without a wake, C++ has a 30-second watchdog thread, and Kotlin uses
withTimeout(30.seconds).Verified:
just ffi moq,just check,just test. Locally C passed 30/30 runs, C++ 30/30 and Kotlin 10/10. C and C++ each finish the whole script in about 50 ms.The automated review found a race in the C++ runtime that the C++ round trip exposed, fixed here in
runtime/rt.hpp:idle -> queuedand pause before posting to the executor. Ataskdestroyed in that window returned at once, and the late post then called an executor its owner may already have destroyed.cancel()takes that lock after marking the task done. Once destroying a task returns, its executor is never called again. This holds forthen,via, and a task cancelled from its own callback. Thetask,then, andviadocs andffi/README.mdnow say so.tests/api.cppuses an executor whose second call, the wake's post, blocks on a latch. It destroys the task on another thread while the executor is blocked, and fails if the destroy returns before the latch is released. Before the fix it failed 20 of 20 runs, and after it passes 20 of 20 at each C++ standard.moq.cpp: with the barrier, its worker no longer needs shared queue state, so it is back to a plain worker joined after its task is destroyed.The quest is done, so this PR also:
quest/m1/ffi-export/session-tokio.mdand its links, and dropssession-quic.md's dangling link to it;ffi/README.md, whose description ofmoq/moq.cstill listed the binary-track publish chore: bump the moq pin past moq-tokio's fallback runtime #196 removed;ffi/README.mdthat Rust may call a waker'swakeanddropfrom any thread, asruntime/rt.rsalready requires.Impact
task, fromthenor a coroutine awaitingvia, now waits out a post to the executor already under way. After that, the executor is never called again, so an executor may be destroyed right after its tasks.ffi/README.mdnow states the existing waker contract thatwakeanddropmay come from any thread.Alternatives
bind,acceptandRequest::okinstead ofserve_publish. This is more code per language and doesn't exercise the one-call path the quest's Goal names.Follow-ups
🤖 Generated with Claude Code
(Written by Claude Opus 5.5)