chore: better error ignore
This commit is contained in:
parent
6c76312e5c
commit
1dbefc40c8
2 changed files with 10 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue