From 2b7c015aa51a3630db089fbb922f7be40309da44 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Wed, 5 Feb 2020 15:31:50 +0100 Subject: [PATCH] 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 --- protocols/gossipsub/src/handler.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/protocols/gossipsub/src/handler.rs b/protocols/gossipsub/src/handler.rs index adafe2dc..3c045d52 100644 --- a/protocols/gossipsub/src/handler.rs +++ b/protocols/gossipsub/src/handler.rs @@ -234,20 +234,20 @@ where } Some(InboundSubstreamState::Closing(mut substream)) => { 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; if self.outbound_substream.is_none() { self.keep_alive = KeepAlive::No; } 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 => { self.inbound_substream = Some(InboundSubstreamState::Closing(substream)); @@ -297,6 +297,7 @@ where } } Poll::Ready(Err(e)) => { + debug!("Outbound substream error while sending output: {:?}", e); return Poll::Ready(ProtocolsHandlerEvent::Close(e)); } Poll::Pending => {