Skip to content

fix(net): a socket endpoint's every ending runs its cleanup - #8825

Merged
kixelated merged 2 commits into
mainfrom
quest/m1/socket-endpoint-end
Nov 15, 2026
Merged

kixelated merged 2 commits into
mainfrom
quest/m1/socket-endpoint-end

Conversation

@kixelated

@kixelated kixelated commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Finishes quest/m1/socket-endpoint-end.md.

Summary

  • moq_net::socket::Endpoint keeps its lifecycle in one State: Open(Box<Open>), which holds the routes, handler, queued dials, waiters, and handed-out streams, or Closed(Error). Handler::None now means only "not made yet". The separate end: Option<Error> is gone.
  • Every ending goes through one Shared::end(err): close(), drop, the server handler reporting its broadcast ended (which used to record the error and retire only the handler, leaving the client route, queued dials, and handed-out streams open), and poll_end finding a route broadcast closed (which used to return Closed without recording it or cleaning up). end moves the whole Open out under the lock and does the cleanup outside it, as close did before.
  • socket::is_endpoint reaches every binding: moq_socket_is_endpoint in moq-ffi (UniFFI, so C++ gets it generated) and in moq-c, plus Python moq.socket.is_endpoint, Go socket.IsEndpoint, Kotlin dev.moq.socket.isEndpoint, Swift Socket.isEndpoint, and Dart isEndpoint (raw Dart bindings regenerated). The socket guide (doc/concept/socket.md) says what it is for and lists the name in each language.

Public API

  • Additive: moq_socket_is_endpoint(path) -> Result<bool, MoqError> (moq-ffi), moq_socket_is_endpoint(path, path_len) -> i32 (moq-c: 1, 0, or a negative code), plus the wrapper functions above. A malformed path fails rather than reading as "not an endpoint".
  • Behavior: when an endpoint's broadcast ends, the endpoint now ends fully, so the sessions it handed out get reset.
  • Wire: none.

Decisions (made while AFK; a review can undo them)

  • No waker that ends the endpoint the moment a route broadcast closes. In Rust, an endpoint's routes are private, and origin teardown doesn't close local route broadcasts (the route keeps the driver alive). So the only thing that can close them is the endpoint's own end, and catching the ending in poll_end and poll_dial covers every reachable case. JS needs onClosed and origin.closed hooks because there the origin can close underneath it. If Rust ever exposes the routes or closes local routes on teardown, register a Waker on each route's poll_closed that calls end.
  • is_endpoint over FFI takes a string and errors on an invalid path, following the fail-loud rule. The other choice was returning false.
  • State::Open is boxed to satisfy clippy's large_enum_variant. It costs one allocation per endpoint.
  • The session-reset error stays Session(Cancel) for every ending, as close already used.

Validation

  • New unit test a_broadcast_ending_ends_the_endpoint: alice and bob connect on one origin, then bob's server broadcast is closed by hand. After that, bob's accept fails with Closed, his handed-out half refuses writes, and his dial fails with Closed. Run against the old code with the old state shape, it fails ("a handed-out half outlived the end"); it passes now.
  • The existing taking_a_dial_wakes_outside_the_lock and abandoned_dials_leave_the_queue tests pass, which covers re-entering through an inline executor.
  • moq_socket_is_endpoint is tested in moq-ffi (test::socket_is_endpoint) and moq-c (test::parity::socket_is_endpoint): server and client paths, a media path, and a malformed path.
  • just check passes. That covers Rust (clippy, nextest including the socket integration tests through a relay), py, go, kt, swift, dart, c, and cpp.
  • just test interop --all passes, including "Python/Rust sockets (moq-lite-07-wip), both roles".
  • Not run: calling the new wrapper functions directly from each language. A Python one-liner via uv run timed out on a cold build. The wrappers are one-line pass-throughs, and the wrapper checks compiled and imported them.

Caused by

  • moq-dev/moq#7677: introduced poll_end returning Closed when the publication closed without recording the end or running close(), with end kept beside the handler state. (found by reviewer, the release feature review)

Follow-ups

None.

Models

Size: S
Implementer: Claude Code, claude-opus-5-5, unknown effort (arm A)

🤖 Generated with Claude Code

Review

Rewritten by quest review after each round.

  • Head: 38e1af3

  • Base: origin/main at ca88fc1

  • Risk: medium, the base has no RISK.md to name what is always high or customer-facing, so every change is medium

  • Classified: medium by default

  • Reviewer: Codex, gpt-6.1-sol, medium effort

  • Session: 01a1df9d-0f8c-7fe3-91ea-99617b7e7149, round 1

  • Score: 9/10, The lifecycle refactor preserves existing behavior while centralizing cleanup, with no actionable defects identified; builds and tests were not run, as instructed.

  • Rounds: 1; first round 0; findings 0: fixed 0, refuted 0, open 0

  • Findings: none

kixelated and others added 2 commits November 15, 2026 04:34
The endpoint's lifecycle is one State (Open | Closed(Error)), and every ending
(close, drop, the server handler ending, a broadcast closing) goes through
Shared::end. socket::is_endpoint reaches moq-ffi, moq-c, and every wrapper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title A socket endpoint's every ending runs its cleanup fix(net): a socket endpoint's every ending runs its cleanup Nov 15, 2026
@kixelated
kixelated marked this pull request as ready for review November 15, 2026 14:31
@coderabbitai

coderabbitai Bot commented Nov 15, 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 31 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: 24f53c90-6965-4eaa-b8cb-2c87196bdc0e
Commits

Reviewing files that changed from the base of the PR and between fabfe5e and 38e1af3.

Files selected for processing: 14

  • dart/moq/lib/socket.dart
  • dart/moq_ffi/lib/src/moq.dart
  • doc/concept/socket.md
  • go/wrapper/socket/socket.go
  • kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/socket/Socket.kt
  • py/moq-rs/moq/socket.py
  • quest/m1/socket-endpoint-end.md
  • rs/moq-c/README.md
  • rs/moq-c/src/socket.rs
  • rs/moq-c/src/test/parity.rs
  • rs/moq-ffi/src/socket.rs
  • rs/moq-ffi/src/test.rs
  • rs/moq-net/src/model/socket.rs
  • swift/Sources/Moq/Socket.swift
  • 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

@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 new issues found.

Reviewed changes

I read the full diff: the socket endpoint's lifecycle refactor in moq-net and the is_endpoint additions across FFI, C, and every wrapper.

  • One lifecycle State: socket::Endpoint now holds Open(Box<Open>) | Closed(Error) in place of end: Option<Error> beside the handler, and Handler::None now means only "not made yet".
  • One Shared::end(err): close, drop, the server Requests ending in poll_dial, and poll_end seeing a route broadcast closed all run the same cleanup. end swaps in Closed under the lock, then outside the lock it aborts the handed-out halves, closes both broadcasts, rejects the queued dials, and wakes the accepts and any waiters on a taken handler.
  • poll_dial ended path: it calls end before dropping the handler, which keeps the old Unroutable-over-Dropped ordering, then rejects the dials it took with Cancel.
  • is_endpoint everywhere: moq_socket_is_endpoint is added in moq-ffi (it throws on a malformed path) and moq-c (returns 1, 0, or a negative code). Python, Go, Kotlin, Swift, and Dart get wrappers, and doc/concept/socket.md lists the name in each language.

I checked that an endpoint's routes come from origin::Producer::route → exact(), which sets no request validity. So in production only end itself closes them, as the "no waker" decision says. The new poll_end → end path is defensive, and end is idempotent, so a race with a concurrent close just returns the recorded error.

Pullfrog  | View workflow run | Using claude-opus-5-5 | 𝕏

@kixelated
kixelated added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit fe859d1 Nov 15, 2026
10 checks passed
@kixelated
kixelated deleted the quest/m1/socket-endpoint-end branch November 15, 2026 19:29
kixelated added a commit that referenced this pull request Nov 15, 2026
Reflow the encode_offer doc under max_width, and name the scope test's third
measurement (closing an idle session) in its doc and assertion. Record the
maintainer's keep of py-socket-abort.md: its first step checks whether #8825
fixed the flake, and it drops the link to the quest #8825 deleted.

Co-Authored-By: Claude Opus 5.5 <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