mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-22 00:21:30 +00:00
Fix timer usage
This commit is contained in:
parent
4a4180bde5
commit
d20a389043
4
box.go
4
box.go
|
@ -235,7 +235,7 @@ func (s *Box) Start() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Box) preStart() error {
|
func (s *Box) preStart() error {
|
||||||
monitor := taskmonitor.New(s.logger, C.DefaultStartTimeout)
|
monitor := taskmonitor.New(s.logger, C.StartTimeout)
|
||||||
monitor.Start("start logger")
|
monitor.Start("start logger")
|
||||||
err := s.logFactory.Start()
|
err := s.logFactory.Start()
|
||||||
monitor.Finish()
|
monitor.Finish()
|
||||||
|
@ -331,7 +331,7 @@ func (s *Box) Close() error {
|
||||||
default:
|
default:
|
||||||
close(s.done)
|
close(s.done)
|
||||||
}
|
}
|
||||||
monitor := taskmonitor.New(s.logger, C.DefaultStopTimeout)
|
monitor := taskmonitor.New(s.logger, C.StopTimeout)
|
||||||
var errors error
|
var errors error
|
||||||
for serviceName, service := range s.postServices {
|
for serviceName, service := range s.postServices {
|
||||||
monitor.Start("close ", serviceName)
|
monitor.Start("close ", serviceName)
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Box) startOutbounds() error {
|
func (s *Box) startOutbounds() error {
|
||||||
monitor := taskmonitor.New(s.logger, C.DefaultStartTimeout)
|
monitor := taskmonitor.New(s.logger, C.StartTimeout)
|
||||||
outboundTags := make(map[adapter.Outbound]string)
|
outboundTags := make(map[adapter.Outbound]string)
|
||||||
outbounds := make(map[string]adapter.Outbound)
|
outbounds := make(map[string]adapter.Outbound)
|
||||||
for i, outboundToStart := range s.outbounds {
|
for i, outboundToStart := range s.outbounds {
|
||||||
|
|
|
@ -199,7 +199,7 @@ func run() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func closeMonitor(ctx context.Context) {
|
func closeMonitor(ctx context.Context) {
|
||||||
time.Sleep(C.DefaultStopFatalTimeout)
|
time.Sleep(C.FatalStopTimeout)
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
|
|
|
@ -11,7 +11,8 @@ const (
|
||||||
UDPTimeout = 5 * time.Minute
|
UDPTimeout = 5 * time.Minute
|
||||||
DefaultURLTestInterval = 3 * time.Minute
|
DefaultURLTestInterval = 3 * time.Minute
|
||||||
DefaultURLTestIdleTimeout = 30 * time.Minute
|
DefaultURLTestIdleTimeout = 30 * time.Minute
|
||||||
DefaultStartTimeout = 10 * time.Second
|
StartTimeout = 10 * time.Second
|
||||||
DefaultStopTimeout = 5 * time.Second
|
StopTimeout = 5 * time.Second
|
||||||
DefaultStopFatalTimeout = 10 * time.Second
|
FatalStopTimeout = 10 * time.Second
|
||||||
|
FakeIPMetadataSaveInterval = 10 * time.Second
|
||||||
)
|
)
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/sagernet/bbolt"
|
"github.com/sagernet/bbolt"
|
||||||
"github.com/sagernet/sing-box/adapter"
|
"github.com/sagernet/sing-box/adapter"
|
||||||
|
C "github.com/sagernet/sing-box/constant"
|
||||||
"github.com/sagernet/sing/common/logger"
|
"github.com/sagernet/sing/common/logger"
|
||||||
M "github.com/sagernet/sing/common/metadata"
|
M "github.com/sagernet/sing/common/metadata"
|
||||||
)
|
)
|
||||||
|
@ -58,12 +59,13 @@ func (c *CacheFile) FakeIPSaveMetadata(metadata *adapter.FakeIPMetadata) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CacheFile) FakeIPSaveMetadataAsync(metadata *adapter.FakeIPMetadata) {
|
func (c *CacheFile) FakeIPSaveMetadataAsync(metadata *adapter.FakeIPMetadata) {
|
||||||
if timer := c.saveMetadataTimer; timer != nil {
|
if c.saveMetadataTimer == nil {
|
||||||
timer.Stop()
|
c.saveMetadataTimer = time.AfterFunc(C.FakeIPMetadataSaveInterval, func() {
|
||||||
}
|
|
||||||
c.saveMetadataTimer = time.AfterFunc(10*time.Second, func() {
|
|
||||||
_ = c.FakeIPSaveMetadata(metadata)
|
_ = c.FakeIPSaveMetadata(metadata)
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
c.saveMetadataTimer.Reset(C.FakeIPMetadataSaveInterval)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CacheFile) FakeIPStore(address netip.Addr, domain string) error {
|
func (c *CacheFile) FakeIPStore(address netip.Addr, domain string) error {
|
||||||
|
|
|
@ -81,7 +81,7 @@ func (s *BoxService) Close() error {
|
||||||
select {
|
select {
|
||||||
case <-done:
|
case <-done:
|
||||||
return
|
return
|
||||||
case <-time.After(C.DefaultStopFatalTimeout):
|
case <-time.After(C.FatalStopTimeout):
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -153,7 +153,7 @@ func (t *Tun) Start() error {
|
||||||
tunInterface tun.Tun
|
tunInterface tun.Tun
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
monitor := taskmonitor.New(t.logger, C.DefaultStartTimeout)
|
monitor := taskmonitor.New(t.logger, C.StartTimeout)
|
||||||
monitor.Start("open tun interface")
|
monitor.Start("open tun interface")
|
||||||
if t.platformInterface != nil {
|
if t.platformInterface != nil {
|
||||||
tunInterface, err = t.platformInterface.OpenTun(&t.tunOptions, t.platformOptions)
|
tunInterface, err = t.platformInterface.OpenTun(&t.tunOptions, t.platformOptions)
|
||||||
|
|
|
@ -422,7 +422,7 @@ func (r *Router) Outbounds() []adapter.Outbound {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Router) PreStart() error {
|
func (r *Router) PreStart() error {
|
||||||
monitor := taskmonitor.New(r.logger, C.DefaultStartTimeout)
|
monitor := taskmonitor.New(r.logger, C.StartTimeout)
|
||||||
if r.interfaceMonitor != nil {
|
if r.interfaceMonitor != nil {
|
||||||
monitor.Start("initialize interface monitor")
|
monitor.Start("initialize interface monitor")
|
||||||
err := r.interfaceMonitor.Start()
|
err := r.interfaceMonitor.Start()
|
||||||
|
@ -451,7 +451,7 @@ func (r *Router) PreStart() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Router) Start() error {
|
func (r *Router) Start() error {
|
||||||
monitor := taskmonitor.New(r.logger, C.DefaultStartTimeout)
|
monitor := taskmonitor.New(r.logger, C.StartTimeout)
|
||||||
if r.needGeoIPDatabase {
|
if r.needGeoIPDatabase {
|
||||||
monitor.Start("initialize geoip database")
|
monitor.Start("initialize geoip database")
|
||||||
err := r.prepareGeoIPDatabase()
|
err := r.prepareGeoIPDatabase()
|
||||||
|
@ -606,7 +606,7 @@ func (r *Router) Start() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Router) Close() error {
|
func (r *Router) Close() error {
|
||||||
monitor := taskmonitor.New(r.logger, C.DefaultStopTimeout)
|
monitor := taskmonitor.New(r.logger, C.StopTimeout)
|
||||||
var err error
|
var err error
|
||||||
for i, rule := range r.rules {
|
for i, rule := range r.rules {
|
||||||
monitor.Start("close rule[", i, "]")
|
monitor.Start("close rule[", i, "]")
|
||||||
|
|
Loading…
Reference in a new issue