chore: better error ignore

This commit is contained in:
wwqgtxx 2023-04-09 23:06:56 +08:00
parent 6c76312e5c
commit 1dbefc40c8
2 changed files with 10 additions and 5 deletions

View file

@ -103,7 +103,7 @@ func (h *ListenerHandler) NewPacketConnection(ctx context.Context, conn network.
dest, err := conn.ReadPacket(buff) dest, err := conn.ReadPacket(buff)
if err != nil { if err != nil {
buff.Release() buff.Release()
if E.IsClosed(err) { if ShouldIgnorePacketError(err) {
break break
} }
return err 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) 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 { type packet struct {
conn *network.PacketConn conn *network.PacketConn
mutex *sync.Mutex mutex *sync.Mutex

View file

@ -6,7 +6,6 @@ import (
"io" "io"
"net" "net"
"net/netip" "net/netip"
"os"
"sync" "sync"
"time" "time"
@ -18,7 +17,6 @@ import (
D "github.com/miekg/dns" D "github.com/miekg/dns"
"github.com/sagernet/sing/common/buf" "github.com/sagernet/sing/common/buf"
E "github.com/sagernet/sing/common/exceptions"
M "github.com/sagernet/sing/common/metadata" M "github.com/sagernet/sing/common/metadata"
"github.com/sagernet/sing/common/network" "github.com/sagernet/sing/common/network"
) )
@ -118,8 +116,7 @@ func (h *ListenerHandler) NewPacketConnection(ctx context.Context, conn network.
dest, err := conn.ReadPacket(buff) dest, err := conn.ReadPacket(buff)
if err != nil { if err != nil {
buff.Release() buff.Release()
// ignore simple error if sing.ShouldIgnorePacketError(err) {
if err == os.ErrDeadlineExceeded || E.IsClosed(err) {
break break
} }
return err return err