Skip to content

Commit 6be6005

Browse files
committed
fix(net): ignore NotConnected error in NetworkStream.close
On OSX, calling shutdown a second time will return a NotConnected error. This commit will just ignore it, since we can agree that if a stream is "not connected", it is in fact "closed". Closes #508
1 parent 67340a5 commit 6be6005

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/net.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! A collection of traits abstracting over Listeners and Streams.
22
use std::any::{Any, TypeId};
33
use std::fmt;
4-
use std::io::{self, Read, Write};
4+
use std::io::{self, ErrorKind, Read, Write};
55
use std::net::{SocketAddr, ToSocketAddrs, TcpStream, TcpListener, Shutdown};
66
use std::mem;
77
use std::path::Path;
@@ -292,10 +292,21 @@ impl NetworkStream for HttpStream {
292292

293293
#[inline]
294294
fn close(&mut self, how: Shutdown) -> io::Result<()> {
295+
#[inline]
296+
fn shutdown(tcp: &mut TcpStream, how: Shutdown) -> io::Result<()> {
297+
match tcp.shutdown(how) {
298+
Ok(_) => Ok(()),
299+
// see https://github.com/hyperium/hyper/issues/508
300+
Err(ref e) if e.kind() == ErrorKind::NotConnected => Ok(()),
301+
err => err
302+
}
303+
}
304+
295305
match *self {
296-
HttpStream::Http(ref mut inner) => inner.0.shutdown(how),
297-
HttpStream::Https(ref mut inner) => inner.get_mut().0.shutdown(how)
306+
HttpStream::Http(ref mut inner) => shutdown(&mut inner.0, how),
307+
HttpStream::Https(ref mut inner) => shutdown(&mut inner.get_mut().0, how)
298308
}
309+
299310
}
300311
}
301312

0 commit comments

Comments
 (0)