From 1dbefc40c8a44744262c6d68e66c6c4620cf5c26 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Sun, 9 Apr 2023 23:06:56 +0800 Subject: [PATCH] chore: better error ignore --- listener/sing/sing.go | 10 +++++++++- listener/sing_tun/dns.go | 5 +---- 2 files changed, 10 insertions(+), 5 deletions(-) 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