From fc63ec9388ddd881735c6fd48733f46c659d0ab0 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Fri, 5 Apr 2024 10:15:56 +0800 Subject: [PATCH] avoid netlink dos networkUpdateMonitor --- monitor_linux.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/monitor_linux.go b/monitor_linux.go index 89c8a58..e92f469 100644 --- a/monitor_linux.go +++ b/monitor_linux.go @@ -4,6 +4,7 @@ import ( "os" "runtime" "sync" + "time" "github.com/sagernet/netlink" E "github.com/sagernet/sing/common/exceptions" @@ -67,6 +68,9 @@ func (m *networkUpdateMonitor) Start() error { } func (m *networkUpdateMonitor) loopUpdate() { + const minDuration = time.Second + timer := time.NewTimer(minDuration) + defer timer.Stop() for { select { case <-m.close: @@ -75,6 +79,12 @@ func (m *networkUpdateMonitor) loopUpdate() { case <-m.linkUpdate: } m.emit() + select { + case <-m.close: + return + case <-timer.C: + timer.Reset(minDuration) + } } }