mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-04-25 11:02:12 +00:00
protocols/gossipsub: Do not close connection when inbound fails (#1424)
Instead of closing the connection on an error on the inbound substream (both on `poll_next` as well as `poll_close`), one can set it to None and depend on the remote to open an new one in case they have more data to send. Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
This commit is contained in:
parent
c73a175963
commit
2b7c015aa5
@ -234,20 +234,20 @@ where
|
|||||||
}
|
}
|
||||||
Some(InboundSubstreamState::Closing(mut substream)) => {
|
Some(InboundSubstreamState::Closing(mut substream)) => {
|
||||||
match Sink::poll_close(Pin::new(&mut substream), cx) {
|
match Sink::poll_close(Pin::new(&mut substream), cx) {
|
||||||
Poll::Ready(Ok(())) => {
|
Poll::Ready(res) => {
|
||||||
|
if let Err(e) = res {
|
||||||
|
// Don't close the connection but just drop the inbound substream.
|
||||||
|
// In case the remote has more to send, they will open up a new
|
||||||
|
// substream.
|
||||||
|
debug!("Inbound substream error while closing: {:?}", e);
|
||||||
|
}
|
||||||
|
|
||||||
self.inbound_substream = None;
|
self.inbound_substream = None;
|
||||||
if self.outbound_substream.is_none() {
|
if self.outbound_substream.is_none() {
|
||||||
self.keep_alive = KeepAlive::No;
|
self.keep_alive = KeepAlive::No;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Poll::Ready(Err(e)) => {
|
|
||||||
debug!("Inbound substream error while closing: {:?}", e);
|
|
||||||
return Poll::Ready(ProtocolsHandlerEvent::Close(io::Error::new(
|
|
||||||
io::ErrorKind::BrokenPipe,
|
|
||||||
"Failed to close stream",
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
Poll::Pending => {
|
Poll::Pending => {
|
||||||
self.inbound_substream =
|
self.inbound_substream =
|
||||||
Some(InboundSubstreamState::Closing(substream));
|
Some(InboundSubstreamState::Closing(substream));
|
||||||
@ -297,6 +297,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Poll::Ready(Err(e)) => {
|
Poll::Ready(Err(e)) => {
|
||||||
|
debug!("Outbound substream error while sending output: {:?}", e);
|
||||||
return Poll::Ready(ProtocolsHandlerEvent::Close(e));
|
return Poll::Ready(ProtocolsHandlerEvent::Close(e));
|
||||||
}
|
}
|
||||||
Poll::Pending => {
|
Poll::Pending => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user