-
Notifications
You must be signed in to change notification settings - Fork 39
Fix a rare race when accepting a stream. #120
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
If the stream is reset before the WebTransport header can be written, then web-transport-quinn was incorrectly returning an error. This can happen naturally under packet loss scenarios or potentially even when an empty stream is reset.
WalkthroughThe pull request modifies error handling in stream acceptance logic across two WebTransport implementations. In Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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: 0
🧹 Nitpick comments (1)
web-transport-quinn/src/session.rs (1)
391-397: LGTM - Good fix for the race condition.The change from propagating errors to logging and continuing correctly addresses the race condition where streams are reset before the WebTransport header can be written. This makes stream acceptance more resilient to packet loss and early resets.
However, consider these improvements:
Error differentiation: The current code treats all decoding errors equally. Consider differentiating between expected errors (early stream resets) and unexpected errors (session ID mismatches, which could indicate protocol violations or bugs).
Observability: Add a counter or metric to track the frequency of these decode failures, which would help with monitoring and debugging in production.
Example refactor for better error handling:
let (typ, recv) = match ready!(self.pending_uni.poll_next_unpin(cx)) { Some(Ok(res)) => res, Some(Err(err)) => { - // Ignore the error, the stream was probably reset early. - log::warn!("failed to decode unidirectional stream: {err:?}"); + // Ignore the error, the stream was probably reset early. + // This is expected under packet loss or when empty streams are reset. + match &err { + SessionError::WebTransport(web_transport_proto::WebTransportError::UnknownSession) => { + log::warn!("stream decode failed with session ID mismatch: {err:?}"); + } + _ => { + log::debug!("stream decode failed (likely early reset): {err:?}"); + } + } continue; } None => return Poll::Pending, };
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
web-transport-quiche/src/connection.rs(2 hunks)web-transport-quinn/src/session.rs(2 hunks)
🔇 Additional comments (3)
web-transport-quinn/src/session.rs (1)
462-468: Consistent error handling for bidirectional streams.The same resilient error handling is applied here as in
poll_accept_uni, which is good for consistency. The same recommendations apply regarding error differentiation and observability.web-transport-quiche/src/connection.rs (2)
427-433: Consistent fix across both implementations.The error handling change here mirrors the quinn implementation, which is excellent for consistency. Using
tracing::warn!with structured logging (?err) provides better observability than plain string formatting.The same recommendations from the quinn implementation apply: consider differentiating between expected errors (early resets) and unexpected errors (protocol violations), and consider adding metrics to track the frequency of these occurrences.
498-504: Consistent bidirectional stream handling.The error handling for bidirectional streams matches the unidirectional implementation, maintaining good consistency.
If the stream is reset before the WebTransport header can be written, then web-transport-quinn was incorrectly returning an error. This can happen naturally under packet loss scenarios or potentially even when an empty stream is reset.
Summary by CodeRabbit