Skip to content

Commit 5e7ffa9

Browse files
authored
Fix a rare race when accepting a stream. (#120)
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.
1 parent 6174875 commit 5e7ffa9

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

web-transport-quiche/src/connection.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,12 @@ impl SessionAccept {
425425

426426
// Poll the list of pending streams.
427427
let (typ, recv) = match ready!(self.pending_uni.poll_next_unpin(cx)) {
428-
Some(res) => res?,
428+
Some(Ok(res)) => res,
429+
Some(Err(err)) => {
430+
// Ignore the error, the stream was probably reset early.
431+
tracing::warn!(?err, "failed to decode unidirectional stream");
432+
continue;
433+
}
429434
None => return Poll::Pending,
430435
};
431436

@@ -491,7 +496,12 @@ impl SessionAccept {
491496

492497
// Poll the list of pending streams.
493498
let res = match ready!(self.pending_bi.poll_next_unpin(cx)) {
494-
Some(res) => res?,
499+
Some(Ok(res)) => res,
500+
Some(Err(err)) => {
501+
// Ignore the error, the stream was probably reset early.
502+
tracing::warn!(?err, "failed to decode bidirectional stream");
503+
continue;
504+
}
495505
None => return Poll::Pending,
496506
};
497507

web-transport-quinn/src/session.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,12 @@ impl SessionAccept {
389389

390390
// Poll the list of pending streams.
391391
let (typ, recv) = match ready!(self.pending_uni.poll_next_unpin(cx)) {
392-
Some(res) => res?,
392+
Some(Ok(res)) => res,
393+
Some(Err(err)) => {
394+
// Ignore the error, the stream was probably reset early.
395+
log::warn!("failed to decode unidirectional stream: {err:?}");
396+
continue;
397+
}
393398
None => return Poll::Pending,
394399
};
395400

@@ -455,7 +460,12 @@ impl SessionAccept {
455460

456461
// Poll the list of pending streams.
457462
let res = match ready!(self.pending_bi.poll_next_unpin(cx)) {
458-
Some(res) => res?,
463+
Some(Ok(res)) => res,
464+
Some(Err(err)) => {
465+
// Ignore the error, the stream was probably reset early.
466+
log::warn!("failed to decode bidirectional stream: {err:?}");
467+
continue;
468+
}
459469
None => return Poll::Pending,
460470
};
461471

0 commit comments

Comments
 (0)