mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-13 01:51:23 +00:00
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:
@ -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()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user