Keep raw inbound handshakes alive during idle shutdown - #464
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes an idle-shutdown race by ensuring inbound raw session handshakes are counted as “pending work” in the service state, preventing the service loop from shutting down before the handshake finishes.
Changes:
- Adds a
tracked_stateflag to handshake success/error session events so only handshakes that actually incremented pending-work will decrement it. - Marks raw-session handshakes as tracked and increments pending-work for inbound raw sessions (matching existing outbound behavior).
- Adds a regression test asserting inbound raw sessions register pending work.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tentacle/src/session.rs | Extends handshake events with tracked_state to indicate whether they should release pending-work state. |
| tentacle/src/service/helper.rs | Plumbs tracked_state through HandshakeContext into emitted handshake events; keeps listener inbound handshakes untracked. |
| tentacle/src/service.rs | Increments state for inbound raw sessions; decrements on handshake completion only when tracked_state is true; adds regression test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
[P2] Process queued raw sessions before the idle-shutdown check The new regression test calls InnerService::handle_service_task directly, so it bypasses the initial idle-shutdown check in Service::run. A caller can obtain ServiceAsyncControl, enqueue an inbound raw_session before starting Service::run, and then run the service. With the default forever(false), run observes no listeners, no sessions, and State::Running(0), exits immediately, and drops the queued raw session before the new state.increase() is reached. I added an end-to-end reproducer through the public control API:
Run: On the exact PR head (8228348), it fails immediately with: As a control, the same test passes if Service::run consumes an already-ready service_task_receiver item before checking for idle shutdown. Please cover this public queued-task path and either drain ready service tasks before the shutdown check or account for queued work when it is enqueued. |
Summary
Fix an idle-shutdown race for inbound raw sessions.
RawSessionInfo::Inboundpreviously started a handshake without registering pending work in the service state. For services running with no listener, no active sessions, andforever(false), the main loop could treat the service as idle and shut down before the inbound raw-session handshake completed.Changes
tracked_stateflag to handshake events so only handshakes that incremented the service state release it on success or failure.Tests
cargo fmt --checkcargo test -p tentacle raw_inbound_session_registers_pending_work -- --nocapturegit diff --check