File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,6 +32,8 @@ type Service struct {
3232 adaptiveTimer * adaptiveTimer
3333 lastReportTime atomic.Int64
3434 //nolint:unused // touched only on darwin && cgo via writeOOMDraft/discardOOMDraft.
35+ lastDraftTime atomic.Int64
36+ //nolint:unused // touched only on darwin && cgo via writeOOMDraft/discardOOMDraft.
3537 draftCancelled atomic.Bool
3638}
3739
Original file line number Diff line number Diff line change @@ -34,13 +34,16 @@ import "C"
3434
3535import (
3636 "sync"
37+ "time"
3738
3839 "github.com/sagernet/sing-box/adapter"
3940 "github.com/sagernet/sing/common/byteformats"
4041 E "github.com/sagernet/sing/common/exceptions"
4142 "github.com/sagernet/sing/service"
4243)
4344
45+ const oomDraftMinInterval = time .Hour
46+
4447var (
4548 globalAccess sync.Mutex
4649 globalServices []* Service
@@ -109,6 +112,14 @@ func (s *Service) writeOOMDraft(memoryUsage uint64) {
109112 if s .draftCancelled .Load () {
110113 return
111114 }
115+ now := time .Now ().UnixNano ()
116+ lastDraft := s .lastDraftTime .Load ()
117+ if time .Duration (now - lastDraft ) < oomDraftMinInterval {
118+ return
119+ }
120+ if ! s .lastDraftTime .CompareAndSwap (lastDraft , now ) {
121+ return
122+ }
112123 reporter := service.FromContext [OOMReporter ](s .ctx )
113124 if reporter == nil {
114125 return
You can’t perform that action at this time.
0 commit comments