From 9e6ba64940f959708aaa6a9a8117846b07f8d1c5 Mon Sep 17 00:00:00 2001 From: Skyxim Date: Thu, 21 Apr 2022 08:08:37 -0700 Subject: [PATCH] fix: add wait timeout, and log --- component/sniffer/dispatcher.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/component/sniffer/dispatcher.go b/component/sniffer/dispatcher.go index e3658d0e..4734bda1 100644 --- a/component/sniffer/dispatcher.go +++ b/component/sniffer/dispatcher.go @@ -5,6 +5,7 @@ import ( "net" "net/netip" "strconv" + "time" "github.com/Dreamacro/clash/component/trie" @@ -85,8 +86,16 @@ func (sd *SnifferDispatcher) Enable() bool { func (sd *SnifferDispatcher) sniffDomain(conn *CN.BufferedConn, metadata *C.Metadata) (string, error) { for _, sniffer := range sd.sniffers { if sniffer.SupportNetwork() == C.TCP { + conn.SetReadDeadline(time.Now().Add(3 * time.Second)) _, err := conn.Peek(1) if err != nil { + _, ok := err.(*net.OpError) + if ok { + log.Errorln("[Sniffer] [%s] Maybe read timeout, Consider adding skip", metadata.DstIP.String()) + conn.Close() + } + + log.Errorln("[Sniffer] %v", err) return "", err }