From beceb6ed44d1ce70b5e7be98cfbb70a02e1fc016 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Fri, 25 Jan 2019 14:38:03 +0100 Subject: [PATCH] Properly close identify substreams (#893) --- protocols/identify/src/protocol.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/protocols/identify/src/protocol.rs b/protocols/identify/src/protocol.rs index 5b80ca96..8be4e6b1 100644 --- a/protocols/identify/src/protocol.rs +++ b/protocols/identify/src/protocol.rs @@ -112,7 +112,8 @@ where T: AsyncWrite } } - try_ready!(self.inner.poll_complete()); + // A call to `close()` implies flushing. + try_ready!(self.inner.close()); Ok(Async::Ready(())) } } @@ -169,6 +170,7 @@ where fn upgrade_outbound(self, socket: C, _: Self::Info) -> Self::Future { IdentifyOutboundFuture { inner: Framed::new(socket, codec::UviBytes::::default()), + shutdown: false, } } } @@ -176,15 +178,22 @@ where /// Future returned by `OutboundUpgrade::upgrade_outbound`. pub struct IdentifyOutboundFuture { inner: Framed>, + /// If true, we have finished shutting down the writing part of `inner`. + shutdown: bool, } impl Future for IdentifyOutboundFuture -where T: AsyncRead +where T: AsyncRead + AsyncWrite, { type Item = RemoteInfo; type Error = IoError; fn poll(&mut self) -> Poll { + if !self.shutdown { + try_ready!(self.inner.close()); + self.shutdown = true; + } + let msg = match try_ready!(self.inner.poll()) { Some(i) => i, None => {