Skip to main content

SessionCloser

Struct SessionCloser 

Source
pub(crate) struct SessionCloser {
    inner: Arc<CloserInner>,
}
Expand description

Where crate::action::Action::CloseSession lands.

A OnceLock<(u32, Bytes)> plus the session’s CancellationToken, and deliberately no Transport handles: the transports own the tasks that own the hooks that reach this, so holding them here would close a reference cycle. The close itself happens where it already happens, in run_with_transport, which reads Self::close_args instead of hard-coding (0, b"proxy session ended").

CloseSession is honoured at every site that returns an Action, including Site::StreamEnd on both data and control streams: a close is session-scoped, so no site can be the wrong one for it.

Fields§

§inner: Arc<CloserInner>

Implementations§

Source§

impl SessionCloser

Source

pub(crate) fn new(cancel: CancellationToken) -> Self

A closer bound to the session’s cancellation token.

Source

pub(crate) fn request(&self, code: u32, reason: Bytes) -> bool

Record a close request and cancel the session.

The first request wins and returns true. A later one changes nothing and returns false — refuse it with Refusal::SessionAlreadyClosing rather than letting the second reason overwrite the first.

Source

pub(crate) fn record(&self, code: u32, reason: Bytes) -> bool

Record a close request without cancelling the session.

The first request wins and returns true, exactly as Self::request does; the only difference is that the session keeps running afterwards.

That difference is the whole reason this exists. A control-plane close has two steps — fix the code and reason, then give the egress queues a bounded window to flush — and Self::request cannot express the first without the second, because it cancels as it records. A caller that used it would end the session before the drain it just asked for had begun, and the drain window would be unobservable.

Nothing else changes: run_with_transport still reads Self::close_args at teardown, so a session recorded this way closes with the recorded pair whenever it does close — whether that is the caller cancelling after its drain, or the peer going away first.

Source

pub(crate) fn is_closing(&self) -> bool

Whether a close has been requested.

session.rs reads Self::requested instead, because it wants the code and the reason as well; this stays as the cheap yes-or-no predicate for callers that need nothing more.

Source

pub(crate) fn requested(&self) -> Option<(u32, Bytes, CloseOrigin)>

What was requested and by whom, if anything.

The origin rides along rather than being a second accessor because the two are set together, under one OnceLock, and a caller that read them in two calls would be writing a race it does not have.

Source

pub(crate) fn close_args(&self) -> (u32, Bytes)

The (code, reason) to hand Transport::close, falling back to the pair the proxy has always used. The origin is deliberately dropped here: it is a fact about this process, and what goes on the wire is what the peer was told. A CONNECTION_CLOSE carrying the control plane asked would be this proxy leaking its own topology into somebody else’s session.

Trait Implementations§

Source§

impl Clone for SessionCloser

Source§

fn clone(&self) -> SessionCloser

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SessionCloser

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more