Avoid logging EOF and ErrClosedPipe errors.

smux Stream.WriteTo may return io.EOF, which breaks the contract of
io.Copy that says it should not return io.EOF. smux.Stream doesn't have
a unidirectional shutdown, so we always end up slamming it shut in both
directions and leave the other direction with a broken pipe.
This commit is contained in:
David Fifield
2020-04-19 02:13:48 -06:00
parent 34b7e82af4
commit e9a98c3aef
2 changed files with 14 additions and 4 deletions
+7 -2
View File
@@ -110,16 +110,21 @@ func handle(local *net.TCPConn, sess *smux.Session, conv uint32) error {
if err != nil {
log.Printf("stream %08x:%d copy stream←local: %v\n", conv, stream.ID(), err)
}
local.CloseRead()
stream.Close()
}()
wg.Add(1)
go func() {
defer wg.Done()
_, err := io.Copy(local, stream)
if err != nil {
if err == io.EOF {
// smux Stream.WriteTo may return io.EOF.
err = nil
}
if err != nil && err != io.ErrClosedPipe {
log.Printf("stream %08x:%d copy local←stream: %v\n", conv, stream.ID(), err)
}
local.Close()
local.CloseWrite()
}()
wg.Wait()
+7 -2
View File
@@ -83,16 +83,21 @@ func handleStream(stream *smux.Stream, upstream *net.TCPAddr, conv uint32) error
if err != nil {
log.Printf("stream %08x:%d copy stream←upstream: %v\n", conv, stream.ID(), err)
}
conn.CloseRead()
stream.Close()
}()
wg.Add(1)
go func() {
defer wg.Done()
_, err := io.Copy(conn, stream)
if err != nil {
if err == io.EOF {
// smux Stream.WriteTo may return io.EOF.
err = nil
}
if err != nil && err != io.ErrClosedPipe {
log.Printf("stream %08x:%d copy upstream←stream: %v\n", conv, stream.ID(), err)
}
conn.Close()
conn.CloseWrite()
}()
wg.Wait()