protocols/req-resp: Panic in inbound upgrade when handler dropped (#1990)

An inbound upgrade should not be polled after the corresponding handler
has been dropped. Enforce this assumption by panicing in such case.
This commit is contained in:
Max Inden
2021-03-11 16:54:18 +01:00
committed by GitHub
parent 2f9c1759e6
commit 0c412fbc1c

View File

@ -101,17 +101,25 @@ where
async move {
let read = self.codec.read_request(&protocol, &mut io);
let request = read.await?;
if let Ok(()) = self.request_sender.send((self.request_id, request)) {
if let Ok(response) = self.response_receiver.await {
let write = self.codec.write_response(&protocol, &mut io, response);
write.await?;
} else {
io.close().await?;
return Ok(false)
}
match self.request_sender.send((self.request_id, request)) {
Ok(()) => {},
Err(_) => panic!(
"Expect request receiver to be alive i.e. protocol handler to be alive.",
),
}
if let Ok(response) = self.response_receiver.await {
let write = self.codec.write_response(&protocol, &mut io, response);
write.await?;
io.close().await?;
// Response was sent. Indicate to handler to emit a `ResponseSent` event.
Ok(true)
} else {
io.close().await?;
// No response was sent. Indicate to handler to emit a `ResponseOmission` event.
Ok(false)
}
io.close().await?;
Ok(true)
}.boxed()
}
}