mirror of
https://github.com/tladesignz/dnstt.git
synced 2026-10-05 21:38:09 +03:00
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:
@@ -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()
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user