diff --git a/listener/sing/sing.go b/listener/sing/sing.go index 2a5a7d50..7421a4f1 100644 --- a/listener/sing/sing.go +++ b/listener/sing/sing.go @@ -103,7 +103,7 @@ func (h *ListenerHandler) NewPacketConnection(ctx context.Context, conn network. dest, err := conn.ReadPacket(buff) if err != nil { buff.Release() - if E.IsClosed(err) { + if ShouldIgnorePacketError(err) { break } return err @@ -128,6 +128,14 @@ func (h *ListenerHandler) NewError(ctx context.Context, err error) { log.Warnln("%s listener get error: %+v", h.Type.String(), err) } +func ShouldIgnorePacketError(err error) bool { + // ignore simple error + if E.IsTimeout(err) || E.IsClosed(err) || E.IsCanceled(err) { + return true + } + return false +} + type packet struct { conn *network.PacketConn mutex *sync.Mutex diff --git a/listener/sing_tun/dns.go b/listener/sing_tun/dns.go index e5ec82e2..dc33be91 100644 --- a/listener/sing_tun/dns.go +++ b/listener/sing_tun/dns.go @@ -6,7 +6,6 @@ import ( "io" "net" "net/netip" - "os" "sync" "time" @@ -18,7 +17,6 @@ import ( D "github.com/miekg/dns" "github.com/sagernet/sing/common/buf" - E "github.com/sagernet/sing/common/exceptions" M "github.com/sagernet/sing/common/metadata" "github.com/sagernet/sing/common/network" ) @@ -118,8 +116,7 @@ func (h *ListenerHandler) NewPacketConnection(ctx context.Context, conn network. dest, err := conn.ReadPacket(buff) if err != nil { buff.Release() - // ignore simple error - if err == os.ErrDeadlineExceeded || E.IsClosed(err) { + if sing.ShouldIgnorePacketError(err) { break } return err