Skip to content

Commit 704b37a

Browse files
authored
Fix stop_sending panic when recv stream is in-flight (#331)
1 parent 154ff8d commit 704b37a

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

h3-quinn/src/lib.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ pub struct RecvStream {
354354
stream: Option<quinn::RecvStream>,
355355
read_chunk_fut: ReadChunkFuture,
356356
is_0rtt: bool,
357+
pending_stop: Option<VarInt>,
357358
}
358359

359360
type ReadChunkFuture = ReusableBoxFuture<
@@ -372,6 +373,7 @@ impl RecvStream {
372373
// Should only allocate once the first time it's used
373374
read_chunk_fut: ReusableBoxFuture::new(async { unreachable!() }),
374375
is_0rtt,
376+
pending_stop: None,
375377
}
376378
}
377379
}
@@ -391,7 +393,10 @@ impl quic::RecvStream for RecvStream {
391393
})
392394
};
393395

394-
let (stream, chunk) = ready!(self.read_chunk_fut.poll(cx));
396+
let (mut stream, chunk) = ready!(self.read_chunk_fut.poll(cx));
397+
if let Some(error_code) = self.pending_stop.take() {
398+
let _ = stream.stop(error_code);
399+
}
395400
self.stream = Some(stream);
396401
Poll::Ready(Ok(chunk
397402
.map_err(convert_read_error_to_stream_error)?
@@ -400,11 +405,12 @@ impl quic::RecvStream for RecvStream {
400405

401406
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
402407
fn stop_sending(&mut self, error_code: u64) {
403-
self.stream
404-
.as_mut()
405-
.unwrap()
406-
.stop(VarInt::from_u64(error_code).expect("invalid error_code"))
407-
.ok();
408+
let error_code = VarInt::from_u64(error_code).expect("invalid error_code");
409+
if let Some(stream) = self.stream.as_mut() {
410+
let _ = stream.stop(error_code);
411+
} else {
412+
self.pending_stop = Some(error_code);
413+
}
408414
}
409415

410416
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]

0 commit comments

Comments
 (0)