Skip to content

fix(go): a cancelled stream read waits for its native call - #8428

Merged
kixelated merged 2 commits into
mainfrom
quest/m0/test-flakes-2/go-recv-cancel
Nov 10, 2026
Merged

kixelated merged 2 commits into
mainfrom
quest/m0/test-flakes-2/go-recv-cancel

Conversation

@kixelated

@kixelated kixelated commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes the lost wakeup behind TestRecvGroupCancelKeepsConsumer and removes its t.Skip.

Cause: bridge.run raced every blocking FFI call against ctx and returned as soon as ctx ended. The goroutine was left inside the generated binding. For a stream read (no object cancel), that native read could still poll Ready after the caller had moved on. Under load it took the group appended right after, release destroyed it, and the next RecvGroup never saw it. The Rust waiter staying registered was not the cause.

Fix: a call without an object cancel now runs inline. The generated binding already cancels its own UniFFI future on ctx and destroys a result nobody receives, so the wrapper waits for it instead of racing it. Object-owned calls (Connect, Accept) keep the race, cancel(), and release.

  • CallRelease had only nil-cancel callers (video.Consumer.Next, Claim.Requested), so its release could never run now. It is deleted, and those callers use Call.
  • New test TestRunWaitsForACallWithoutObjectCancel. The two release tests now use an object cancel, the only path that still abandons a call.

Verification

At a load average near 150, the old call.go failed 3 of 300 -race -count=300 runs (RecvGroup after cancel = context deadline exceeded). With the fix, all 300 passed. just go check passes. Full just check did not run: this is a Go-only change and the host was overloaded.

Impact

Public API: none (bridge is internal). Wire: none. A cancelled stream read now returns once the native future is cancelled, not immediately.

Caused by

  • moq-dev/moq#4519 - the bridge returned early on cancel for stream reads, abandoning a read that could still consume the next item

Models

Size: S
Implementer: Claude Code, Opus 5.5, unknown effort

(Written by Opus 5.5)

Review

Rewritten by quest review after each round.

  • Reviewer: Codex, gpt-6.1-sol, medium effort
  • Session: 01a1c553-effd-7d01-8347-34f7630bf299, round 1
  • Head: 9bc08f5
  • Base: origin/main at cd560bd
  • Score: 9/10, The focused fix prevents abandoned reads from consuming subsequent stream items while preserving object-owned cancellation, with regression coverage and no actionable regressions found by source inspection; builds and tests were not run as instructed.
  • Findings: none

kixelated and others added 2 commits November 10, 2026 01:12
The wrapper returned as soon as ctx ended while the native read kept
polling, so a group appended right after could be taken by the abandoned
read and destroyed. Reads without an object cancel now let the generated
binding cancel its own future and wait for it; CallRelease, now unused,
is gone. Unquarantines TestRecvGroupCancelKeepsConsumer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title The Go wrapper's cancelled-RecvGroup test holds up under load fix(go): a cancelled stream read waits for its native call Nov 10, 2026
@kixelated
kixelated marked this pull request as ready for review November 10, 2026 12:00
@coderabbitai

coderabbitai Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 21 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c8a21b5d-a1c3-4cc1-b5c3-976cb652a9f2
Commits

Reviewing files that changed from the base of the PR and between cd560bd and 9bc08f5.

Files selected for processing: 7

  • go/wrapper/internal/bridge/call.go
  • go/wrapper/internal/bridge/call_test.go
  • go/wrapper/moq_test.go
  • go/wrapper/origin.go
  • go/wrapper/video/video.go
  • quest/m0/test-flakes-2/README.md
  • quest/m0/test-flakes-2/go-recv-cancel.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@kixelated kixelated left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Automated review by review (OpenAI)

Reviewed commit 9bc08f5.

No actionable defects found in the wrapper changes. Calling the nil-cancel path inline removes the wrapper's abandoned read, while the object-owned path retains explicit cancellation, WithoutCancel, and disposal of unreceived handles. The two removed CallRelease callers now receive their results directly, and the restored RecvGroup regression test checks reuse after cancellation. Overall direction: the cancellation ownership split looks sound.

Verification limits: GitHub diff/source review of all seven changed files and surrounding bridge/tests; no builds, race tests, or load reproduction run. Generated Go bindings are not checked into this source tree, so their native-future cancellation and result-cleanup behavior was not independently exercised. The reported 300-run result remains author-provided evidence.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues — three comments still describe the pre-fix behavior.

Reviewed changes

Reviewed the complete diff: the Go FFI bridge now runs a call without an object cancel inline, so a cancelled stream read waits for the generated binding's own future cancellation; CallRelease and video's frame release are removed with their nil-cancel callers moved to Call; the quarantined RecvGroup test is re-enabled with a new bridge unit test; and the quest is deleted.

  • bridge.run: cancel == nil now calls the binding on the caller's goroutine; object-owned calls keep the race, cancel(), and release. This matches the pinned generator's uniffiRustCallAsync, which frees its future on ctx.Done() before returning and destroys a result it completed after losing the race.
  • CallRelease / releaseRead deleted: video.Consumer.Next and Claim.Requested use bridge.Call; no abandoned result exists on the inline path, and the generator's destroyFn covers the enum/optional results these two return.
  • Tests: TestRunWaitsForACallWithoutObjectCancel pins the inline behavior, the two release tests force the racy path with an object cancel, and TestRecvGroupCancelKeepsConsumer drops its t.Skip.
  • Quest: go-recv-cancel.md and its README bullet are removed.

ℹ️ Comments still describe the old racing bridge

Three comments now contradict the code, and one of them records a test as skipped that this PR re-enables. The fixes are comment-only, so this does not block the change.

Technical details
# Stale comments after the inline bridge

## Affected sites
- `quest/m0/test-flakes-2/README.md:246-250` — still says the Go test "is quarantined with `t.Skip` until its child fixes it", but this PR removes the skip and deletes the quest. The README already records resolutions in place (e.g. lines 52-58 and 262-267), so this paragraph should name the fix PR instead.
- `go/wrapper/moq_test.go:1242-1246` — `TestRecvGroupCancelRace` says the native `RecvGroup` "runs on an internal goroutine while ctx ending triggers a concurrent Cancel on the same consumer". `RecvGroup` reaches `run` through `CallHandle(ctx, nil, ...)`, which now calls the binding inline, and ctx ending drops the generated UniFFI future rather than calling `MoqTrackConsumer::cancel`.
- `go/wrapper/internal/bridge/call.go:19` — the summary "run races a blocking FFI call against ctx" now only holds when `cancel != nil`; the paragraphs this PR added say so, but the opening line reads as the opposite.

## Required outcome
- The quest README records that the flake is fixed (or drops the paragraph with the bullet), so no reader thinks the test is still quarantined.
- The two comments describe the inline path and the binding-owned cancellation.

Pullfrog  | Fix it ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@kixelated
kixelated added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit c5b00e2 Nov 10, 2026
14 checks passed
@kixelated
kixelated deleted the quest/m0/test-flakes-2/go-recv-cancel branch November 10, 2026 16:12
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