-
Notifications
You must be signed in to change notification settings - Fork 139
moq-lite: Close session on drop #872
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
Conversation
Implement Drop for Session to automatically close the underlying transport when dropped without an explicit close() call. This fixes an issue where old sessions remained active after reconnection, causing stale events to be replayed. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
WalkthroughA Drop implementation is added to the Session struct in 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@rs/moq-lite/src/session.rs`:
- Around line 46-49: The Drop impl for Session currently always calls
self.session.close(...), causing a double-close when Session::close(self, ...)
is called; modify the Session struct to hold an internal guard (e.g., a bool
like closed or an Option<SessionInner>/Option<Transport>) that tracks whether
the session has already been closed, update Session::close (the consuming
method) to set that guard before returning, and change impl Drop for Session to
check the guard and only call the internal close logic if the session is not
already closed; if needed, factor the actual close implementation into a private
fn close_inner(&mut self, code, reason) so both Session::close and Drop can
invoke it without consuming self.
| impl Drop for Session { | ||
| fn drop(&mut self) { | ||
| self.session.close(Error::Cancel.to_code(), "dropped"); | ||
| } |
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.
Prevent double-close when Session::close() is called explicitly.
Because Session::close(self, …) consumes self, the new Drop runs immediately after and calls close again with Cancel/"dropped". That can override the caller’s error code/reason or cause a duplicate close on transports that aren’t idempotent. Consider guarding drop with an internal flag/Option so explicit close disables the destructor path.
🛠️ Suggested fix (guard Drop with Option)
pub struct Session {
- session: Arc<dyn SessionInner>,
+ session: Option<Arc<dyn SessionInner>>,
}
impl Session {
pub(super) fn new<S: web_transport_trait::Session>(session: S) -> Self {
Self {
- session: Arc::new(session),
+ session: Some(Arc::new(session)),
}
}
/// Close the underlying transport session.
- pub fn close(self, err: Error) {
- self.session.close(err.to_code(), err.to_string().as_ref());
+ pub fn close(mut self, err: Error) {
+ if let Some(session) = self.session.take() {
+ session.close(err.to_code(), err.to_string().as_ref());
+ }
}
/// Block until the transport session is closed.
// TODO Remove the Result the next time we make a breaking change.
pub async fn closed(&self) -> Result<(), Error> {
- let err = self.session.closed().await;
+ let err = self.session.as_ref().expect("session closed").closed().await;
Err(Error::Transport(err))
}
}
impl Drop for Session {
fn drop(&mut self) {
- self.session.close(Error::Cancel.to_code(), "dropped");
+ if let Some(session) = self.session.take() {
+ session.close(Error::Cancel.to_code(), "dropped");
+ }
}
}🤖 Prompt for AI Agents
In `@rs/moq-lite/src/session.rs` around lines 46 - 49, The Drop impl for Session
currently always calls self.session.close(...), causing a double-close when
Session::close(self, ...) is called; modify the Session struct to hold an
internal guard (e.g., a bool like closed or an
Option<SessionInner>/Option<Transport>) that tracks whether the session has
already been closed, update Session::close (the consuming method) to set that
guard before returning, and change impl Drop for Session to check the guard and
only call the internal close logic if the session is not already closed; if
needed, factor the actual close implementation into a private fn
close_inner(&mut self, code, reason) so both Session::close and Drop can invoke
it without consuming self.
Summary
DropforSessionto automatically close the underlying transport when droppedCancel) and reason "dropped"Test plan
just checkpasses🤖 Generated with Claude Code