Skip to content

Commit 039281b

Browse files
committed
fix(client): fix polling dispatch channel after it has closed
1 parent de5dcd7 commit 039281b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/proto/h1/dispatch.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub struct Server<S: HttpService<B>, B> {
3737
pub struct Client<B> {
3838
callback: Option<crate::client::dispatch::Callback<Request<B>, Response<Body>>>,
3939
rx: ClientRx<B>,
40+
rx_closed: bool,
4041
}
4142

4243
type ClientRx<B> = crate::client::dispatch::Receiver<Request<B>, Response<Body>>;
@@ -490,7 +491,8 @@ impl<B> Client<B> {
490491
pub fn new(rx: ClientRx<B>) -> Client<B> {
491492
Client {
492493
callback: None,
493-
rx: rx,
494+
rx,
495+
rx_closed: false,
494496
}
495497
}
496498
}
@@ -505,6 +507,7 @@ where
505507
type RecvItem = ResponseHead;
506508

507509
fn poll_msg(&mut self, cx: &mut task::Context<'_>) -> Poll<Option<Result<(Self::PollItem, Self::PollBody), Never>>> {
510+
debug_assert!(!self.rx_closed);
508511
match self.rx.poll_next(cx) {
509512
Poll::Ready(Some((req, mut cb))) => {
510513
// check that future hasn't been canceled already
@@ -526,8 +529,9 @@ where
526529
}
527530
},
528531
Poll::Ready(None) => {
529-
trace!("client tx closed");
530532
// user has dropped sender handle
533+
trace!("client tx closed");
534+
self.rx_closed = true;
531535
Poll::Ready(None)
532536
},
533537
Poll::Pending => Poll::Pending,
@@ -555,7 +559,7 @@ where
555559
if let Some(cb) = self.callback.take() {
556560
let _ = cb.send(Err((err, None)));
557561
Ok(())
558-
} else {
562+
} else if !self.rx_closed {
559563
self.rx.close();
560564
if let Some((req, cb)) = self.rx.try_recv() {
561565
trace!("canceling queued request with connection error: {}", err);
@@ -566,6 +570,8 @@ where
566570
} else {
567571
Err(err)
568572
}
573+
} else {
574+
Err(err)
569575
}
570576
}
571577
}

0 commit comments

Comments
 (0)