chore: better error ignore

This commit is contained in:
gVisor bot 2023-04-09 23:06:56 +08:00
parent c305ea2b7a
commit a0ddce0c6f
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)
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

View file

@ -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