mirror of
https://github.com/tladesignz/dnstt.git
synced 2026-09-22 23:07:59 +03:00
Use errors.Is to compare against ErrClosedPipe.
I was still getting "io: read/write on closed pipe" errors in the logs, even after comparing errors against io.ErrClosedPipe to skip logging them. It turns out that kcp-go wraps many of its errors in another type. The actual type of the errors was *errors.withStack, where errors is https://github.com/pkg/errors. We can use the go1.13 errors interface (https://blog.golang.org/go1.13-errors) to get at the value inside.
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -95,7 +96,7 @@ func handle(local *net.TCPConn, sess *smux.Session, conv uint32) error {
|
||||
// smux Stream.Write may return io.EOF.
|
||||
err = nil
|
||||
}
|
||||
if err != nil && err != io.ErrClosedPipe {
|
||||
if err != nil && !errors.Is(err, io.ErrClosedPipe) {
|
||||
log.Printf("stream %08x:%d copy stream←local: %v", conv, stream.ID(), err)
|
||||
}
|
||||
local.CloseRead()
|
||||
@@ -108,7 +109,7 @@ func handle(local *net.TCPConn, sess *smux.Session, conv uint32) error {
|
||||
// smux Stream.WriteTo may return io.EOF.
|
||||
err = nil
|
||||
}
|
||||
if err != nil && err != io.ErrClosedPipe {
|
||||
if err != nil && !errors.Is(err, io.ErrClosedPipe) {
|
||||
log.Printf("stream %08x:%d copy local←stream: %v", conv, stream.ID(), err)
|
||||
}
|
||||
local.CloseWrite()
|
||||
|
||||
@@ -38,6 +38,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/base32"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -205,7 +206,7 @@ func handleStream(stream *smux.Stream, upstream string, conv uint32) error {
|
||||
// smux Stream.Write may return io.EOF.
|
||||
err = nil
|
||||
}
|
||||
if err != nil && err != io.ErrClosedPipe {
|
||||
if err != nil && !errors.Is(err, io.ErrClosedPipe) {
|
||||
log.Printf("stream %08x:%d copy stream←upstream: %v", conv, stream.ID(), err)
|
||||
}
|
||||
upstreamTCPConn.CloseRead()
|
||||
@@ -218,7 +219,7 @@ func handleStream(stream *smux.Stream, upstream string, conv uint32) error {
|
||||
// smux Stream.WriteTo may return io.EOF.
|
||||
err = nil
|
||||
}
|
||||
if err != nil && err != io.ErrClosedPipe {
|
||||
if err != nil && !errors.Is(err, io.ErrClosedPipe) {
|
||||
log.Printf("stream %08x:%d copy upstream←stream: %v", conv, stream.ID(), err)
|
||||
}
|
||||
upstreamTCPConn.CloseWrite()
|
||||
@@ -302,11 +303,7 @@ func acceptSessions(ln *kcp.Listener, privkey []byte, mtu int, upstream string)
|
||||
conn.Close()
|
||||
}()
|
||||
err := acceptStreams(conn, privkey, upstream)
|
||||
if err == io.ErrClosedPipe {
|
||||
// We don't want to report this error.
|
||||
err = nil
|
||||
}
|
||||
if err != nil {
|
||||
if err != nil && !errors.Is(err, io.ErrClosedPipe) {
|
||||
log.Printf("session %08x acceptStreams: %v", conn.GetConv(), err)
|
||||
}
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user