Ignore closed and canceled errors in scope cleanup

This commit is contained in:
世界
2026-10-23 19:57:02 +08:00
parent 299655ce04
commit f7621b4a47
+6 -3
View File
@@ -9,6 +9,7 @@ import (
"github.com/sagernet/sing-box/common/taskmonitor"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing/common"
E "github.com/sagernet/sing/common/exceptions"
F "github.com/sagernet/sing/common/format"
)
@@ -131,11 +132,13 @@ func (s *Scope) Close() error {
s.cleanups = nil
s.children = nil
s.access.Unlock()
var err error
var cleanupErrors []error
for _, cleanup := range slices.Backward(cleanups) {
err = E.Errors(err, cleanup())
cleanupErrors = append(cleanupErrors, E.Expand(cleanup())...)
}
return err
return E.Errors(common.Filter(cleanupErrors, func(it error) bool {
return !E.IsClosed(it) && !E.IsCanceled(it)
})...)
}
func LogElapsed(logger log.ContextLogger, description ...any) func() {