Skip to content

Unify APIs for Endpoint::closed, Connection::closed and Connection::on_closed #3959

@matheus23

Description

@matheus23

We have ⁨Connection::closed⁩, ⁨Connection::on_closed⁩ and in the future we'll have an ⁨Endpoint::closed⁩ as well. All three work differently. We should unify them.

To detail what they do:

  • Connection::closed resolves to ConnectionError once the connection is closed. The future is lifetime-bound to self, i.e. prevents the connection from being dropped (and thus close-on-drop) while the future is alive
  • Connection::on_closed resolves to (ConnectionError, ConnectionStats) once the connection is closed. The future is 'static and does not store a strong reference to the Connection, thus does not prevent the connection from being closed-on-drop when all other clones are dropped. We use this e.g. in the RemoteStateActor to get a notification once a connection is closed, but without keeping it alive while polling that future, which is what we want here.
  • Endpoint::closed (to be added in the endpoint close PR) returns a CancellationToken, which does not keep the Endpoint alive, and can be used to resolve when the endpoint is closed, or to stop futures when the endpoint closes. I.e. it behaves like Connection::on_closed, with the benefit of being a cancellation token, thus having some util methods (i.e. token.run_until_cancelled(fut))

I think since that was written, Endpoint::closed was changed to return a custom struct that implements Future.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    👍 Ready

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions