-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add Connection::on_close to get notified on close without keeping the connection alive
#153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main-iroh
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine. We should probably submit this upstream too?
quinn/src/connection.rs
Outdated
| /// Returns the reason why the connection was closed and the final [`ConnectionStats`]. | ||
| pub fn on_closed( | ||
| &self, | ||
| ) -> impl Future<Output = (ConnectionError, ConnectionStats)> + Send + Sync + 'static { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the Quinn convention is to name the returned futures? IIRC the main difference is that they can be stored in structs easily when named, instead of needing boxing. I don't really know how strong this convention is. But looking at Connection this now seems like the odd one out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it to make the future public
|
Could you add a little more motivation to the description though? Where do we need this that we can't do any existing way? |
Sure. It depends on the |
|
Added some motivation. I think it could also be useful for the endoint state actor in iroh on the multipath branch? To clean up state once a connection is closed. |
Oh right. That's true. Never mind then. |
8011dfa to
da312ea
Compare
This adds
Connection::on_close, which returns a future that resolves to(ConnectionError, ConnectionStats)without keeping the connection alive. I.e. if all other clones of aConnectionare dropped, the connection will be closed implicitly, and the future will resolve.Motivation: There's a few situations in which you might want to await a connection being closed without keeping the connection alive:
Connectionbecause that would keep the connection alive. But to clean up its local state, it wants to get a notification when the connection is closed. This PR allows for that.on_closedcan be called right after the connection is opened or accepted from a central place, and the future can be sent to a stats tracker. Without this change, all tasks that deal with connections would need to be aware of the stats tracker to sent the final connection stats after the connection is closed to the stats tracker. This is possible, but does not allow for easy and centralized stats tracker as it needs support from all code that deals with connections.