From acea5ea76c5a80ae23e779ad018e97dbbf16b3cc Mon Sep 17 00:00:00 2001 From: sagit Date: Fri, 13 Feb 2026 05:09:54 +0000 Subject: [PATCH] fix(gost): filter expected net.ErrClosed noise in service handler Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus --- go-gost/x/service/service.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/go-gost/x/service/service.go b/go-gost/x/service/service.go index 0ae6c00..1819c64 100644 --- a/go-gost/x/service/service.go +++ b/go-gost/x/service/service.go @@ -54,10 +54,10 @@ var needWrap = false // SetProtocolBlock sets protocol blocking switches and recomputes wrapper need func SetProtocolBlock(httpOn int, tlsOn int, socksOn int) { - isHttp = httpOn - isTls = tlsOn - isSocks = socksOn - needWrap = isTls+isSocks+isHttp > 0 + isHttp = httpOn + isTls = tlsOn + isSocks = socksOn + needWrap = isTls+isSocks+isHttp > 0 } type Option func(opts *options) @@ -292,7 +292,9 @@ func (s *defaultService) Serve() error { } if err := s.handler.Handle(ctx, conn); err != nil { - log.Error(err) + if !errors.Is(err, net.ErrClosed) { + log.Error(err) + } if v := xmetrics.GetCounter(xmetrics.MetricServiceHandlerErrorsCounter, metrics.Labels{"service": s.name, "client": clientIP}); v != nil { v.Inc() @@ -403,12 +405,12 @@ func (s *defaultService) observeStats(ctx context.Context) { TotalErrs: st.Get(stats.KindTotalErrs), }, } - + // 将流量累积到全局管理器,而不是立即上报 if outputBytes > 0 || inputBytes > 0 { globalManager := GetGlobalTrafficManager() globalManager.AddTraffic(s.name, int64(outputBytes), int64(inputBytes)) - + // 立即重置流量计数(因为已经记录到全局管理器中) if xstats, ok := st.(*xstats.Stats); ok { xstats.ResetTraffic(st.Get(stats.KindInputBytes)-inputBytes, st.Get(stats.KindOutputBytes)-outputBytes)