Repository navigation
fix(net): a socket endpoint's every ending runs its cleanup - #8825
Conversation
Quest-Claim: fe0a14a5949391cf
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>
|
Warning Review limit reachedYou'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. View limit details
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. |
There was a problem hiding this comment.
✅ 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::Endpointnow holdsOpen(Box<Open>) | Closed(Error)in place ofend: Option<Error>beside the handler, andHandler::Nonenow means only "not made yet". - One
Shared::end(err):close, drop, the serverRequestsending inpoll_dial, andpoll_endseeing a route broadcast closed all run the same cleanup.endswaps inClosedunder 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_dialended path: it callsendbefore dropping the handler, which keeps the oldUnroutable-over-Droppedordering, then rejects the dials it took withCancel.is_endpointeverywhere:moq_socket_is_endpointis 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, anddoc/concept/socket.mdlists 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.
claude-opus-5-5 | 𝕏
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>

Finishes
quest/m1/socket-endpoint-end.md.Summary
moq_net::socket::Endpointkeeps its lifecycle in oneState:Open(Box<Open>), which holds the routes, handler, queued dials, waiters, and handed-out streams, orClosed(Error).Handler::Nonenow means only "not made yet". The separateend: Option<Error>is gone.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), andpoll_endfinding a route broadcast closed (which used to returnClosedwithout recording it or cleaning up).endmoves the wholeOpenout under the lock and does the cleanup outside it, asclosedid before.socket::is_endpointreaches every binding:moq_socket_is_endpointin moq-ffi (UniFFI, so C++ gets it generated) and in moq-c, plus Pythonmoq.socket.is_endpoint, Gosocket.IsEndpoint, Kotlindev.moq.socket.isEndpoint, SwiftSocket.isEndpoint, and DartisEndpoint(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
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".Decisions (made while AFK; a review can undo them)
end, and catching the ending inpoll_endandpoll_dialcovers every reachable case. JS needsonClosedandorigin.closedhooks because there the origin can close underneath it. If Rust ever exposes the routes or closes local routes on teardown, register aWakeron each route'spoll_closedthat callsend.is_endpointover FFI takes a string and errors on an invalid path, following the fail-loud rule. The other choice was returningfalse.State::Openis boxed to satisfy clippy'slarge_enum_variant. It costs one allocation per endpoint.Session(Cancel)for every ending, asclosealready used.Validation
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 withClosed, his handed-out half refuses writes, and his dial fails withClosed. Run against the old code with the old state shape, it fails ("a handed-out half outlived the end"); it passes now.taking_a_dial_wakes_outside_the_lockandabandoned_dials_leave_the_queuetests pass, which covers re-entering through an inline executor.moq_socket_is_endpointis 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 checkpasses. That covers Rust (clippy, nextest including the socket integration tests through a relay), py, go, kt, swift, dart, c, and cpp.just test interop --allpasses, including "Python/Rust sockets (moq-lite-07-wip), both roles".uv runtimed out on a cold build. The wrappers are one-line pass-throughs, and the wrapper checks compiled and imported them.Caused by
poll_endreturningClosedwhen the publication closed without recording the end or runningclose(), withendkept 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 reviewafter 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 mediumClassified: medium by default
Reviewer: Codex, gpt-6.1-sol, medium effort
Session:
01a1df9d-0f8c-7fe3-91ea-99617b7e7149, round 1Score: 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