async fn serve_session_commands(
inbox: Receiver<SessionCommand>,
ctx: ForwardCtx,
)Expand description
Serve one session’s control-plane requests until the session ends.
Runs beside the forwarding tasks rather than among them, because the
JoinSet in run_with_transport reads the first completion as the end
of the session and this loop finishes on its own terms — when the inbox
closes, or when the session is cancelled.
The cancellation branch is what makes the loop terminate for a session that ends normally: the inbox’s sender lives in the control plane’s registry entry, which is released by the registration guard after this function’s spawner has already returned, so waiting only on the channel would keep the task alive past the session it belongs to.
The select is biased so that branch is polled first. That makes
cancellation the single exit for a session that is going down, whichever
way it was asked: a request that ends the session cancels and goes round
again, and the next poll leaves through the same door as a session that
was cancelled from outside. The alternative — returning from the request
arm — would give the same event two exits to keep correct.