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:
Max Inden 2020-02-05 15:31:50 +01:00 committed by GitHub
parent c73a175963
commit 2b7c015aa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 => {