Repository navigation
perf(node): last-out serve-miss observer joins the pull, freeing a finished owner - #1664
Conversation
…nished owner Follow-up from B3 multi-observer coalescing (#1660). Both serve-miss orchestrations (`serve_via_window_pull_through`, `serve_via_backend_origin`) had the pull OWNER park in `spawn_blocking(pull_thread.join()).await` right after its OWN serve leg returned. When the owner's client finished first while an `Attach` observer was still streaming, the owner's accept task stayed blocked in that join until the pull ended — bounded (the pull ends on fill-completion or the last observer's lease-drop cancel), but it held the finished owner's QUIC/accept-task and a blocking-pool thread longer than necessary. Park the pull-thread `JoinHandle` on the shared `FillSession` and hand it back only to whichever observer leaves LAST, so a non-last-out owner returns at once: - `FillSession` gains `pull_thread: StdMutex<Option<JoinHandle<()>>>` with `set_pull_handle` (owner parks it after spawn) and private `take_pull_handle`. - `ObserverLease::release() -> Option<JoinHandle<()>>` shares one `teardown()` with `Drop` (idempotent via an `armed` flag). Teardown runs the identical last-out decrement + map-removal + cancel UNDER the registry map lock (the B3.2 resurrection-race fix), and returns the parked handle only on the last-out drop. It TAKES the handle under the lock but never JOINS there; the node's async teardown joins off-task via `spawn_blocking`. `detach()` is removed. - Both orchestrations park the handle on the owner branch and, in every teardown (owner and attach), join iff `release()` yields a handle. Invariants preserved: #1610 (last observer cancels the pull, no orphan ingest), #852 `SettleOnDrop` buyer-watermark (runs inside the pull leg regardless of joiner), and the pull thread is always joined by the last-out observer, never detached. Mechanism covered by new unit tests in `fill_session.rs` (`last_out_release_takes_the_pull_handle`, `last_out_release_without_a_parked_handle_returns_none`). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Coverage reportTotal: 80.55% (was 80.57%, ▼ 0.02%) — 62914/78101 lines
History
|
|
Warning Review limit reached
Next review available in: 25 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (2)
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
There was a problem hiding this comment.
Pull request overview
This PR refactors serve-miss coalescing teardown so the upstream pull thread is joined by the last observer to leave, allowing a non-last-out owner (whose client finishes first) to return immediately instead of blocking on join().
Changes:
- Added pull-thread handle parking to
decdn_cache::FillSession, with last-out transfer viaObserverLease::release(). - Updated both serve-miss orchestrations in the node window handler to park the handle on the session and join only when
release()returns a handle. - Added unit tests covering handle handoff and spawn-failure parity.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/cache/src/fill_session.rs | Stores the pull thread JoinHandle on FillSession, adds last-out release() semantics, and adds tests for handle handoff. |
| crates/node/src/handlers/client/window.rs | Parks pull thread handles on the shared session and joins them only on last-out lease release for both owner and attach paths. |
Suppressed comments (1)
crates/cache/src/fill_session.rs:489
ObserverLease::Dropcurrently discards theJoinHandlereturned byteardown(). On a last-out implicit drop (e.g., task cancellation/shutdown before explicitrelease()runs), that drops theJoinHandleand detaches the pull thread, contradicting the stated invariant that the pull thread is always joined by the last observer. Consider joining off-thread here whenteardown()returns a handle so an implicit drop can’t silently detach.
impl Drop for ObserverLease {
fn drop(&mut self) {
let _ = self.teardown();
}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…andle Address Copilot review on #1664: overwriting an already-parked JoinHandle would drop the first handle and detach its thread, orphaning a pull that keeps paying/draining — violating the "always joined" guarantee. It cannot happen today (FillRegistry::claim returns exactly one Owner per session, so the owner parks once), but harden the setter against a future regression: keep the first handle (the one the last-out observer joins) and debug_assert the double-park loudly in tests/dev. Co-Authored-By: Claude Opus 4.8 <[email protected]>
What
Follow-up from B3 multi-observer coalescing (#1660). A self-flagged, bounded lifecycle inefficiency — not a bug.
Both serve-miss orchestrations (
serve_via_window_pull_through,serve_via_backend_origin) had the pull owner park inspawn_blocking(pull_thread.join()).awaitright after its own serve leg returned. When the owner's client finished first while anAttachobserver was still streaming, the owner's accept task stayed blocked in that join until the pull ended — bounded (the pull ends on fill-completion or the last observer's lease-drop cancel), but it held the finished owner's QUIC/accept-task and a blocking-pool thread longer than necessary.Change
Park the pull-thread
JoinHandleon the sharedFillSessionand hand it back only to whichever observer leaves last, so a non-last-out owner returns immediately.crates/cache/src/fill_session.rsFillSessiongainspull_thread: StdMutex<Option<JoinHandle<()>>>withset_pull_handle(owner parks it after spawn) and privatetake_pull_handle.ObserverLease::release() -> Option<JoinHandle<()>>shares oneteardown()withDrop(idempotent via anarmedflag). Teardown runs the identical last-out decrement + map-removal + cancel under the registry map lock (B3.2 resurrection-race fix), and returns the parked handle only on the last-out drop. It takes the handle under the lock but never joins there; the node's async teardown joins off-task viaspawn_blocking.detach()is removed.crates/node/src/handlers/client/window.rsrelease()yields a handle. So an attached observer that leaves last joins the owner's thread; a finished owner returns at once.Invariants preserved
SettleOnDrop— runs inside the pull leg regardless of who joins.ObserverLease::dropstill runs under the registry map lock and does no blocking join there (it only takes the handle).Tests / gate
fill_session.rsdrove the mechanism —last_out_release_takes_the_pull_handle(non-last-out owner →None, returns at once, no cancel; last observer →Some, joins, cancels) andlast_out_release_without_a_parked_handle_returns_none(spawn-failure parity).cargo fmt --all --check, clippy (cache + node, no warnings), 1338 node+cache tests pass, andcargo test --no-run -p decdn-e2e --features anvil-e2ecompiles.🤖 Generated with Claude Code