From 3f014564802c9f7fc87dc1d7a2a94b31121bb915 Mon Sep 17 00:00:00 2001 From: ginuerzh Date: Sun, 21 Jun 2026 20:34:41 +0800 Subject: [PATCH] fix(metrics): skip connection wrapping when metrics are disabled When xmetrics.IsEnabled() is false (no -api / no metrics.addr configured), WrapListener now returns the listener unchanged instead of wrapping every accepted connection in a metrics.serverConn. This allows bare *net.TCPConn to reach the forwarding layer, enabling future splice(2) optimization. --- metrics/wrapper/listener.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/metrics/wrapper/listener.go b/metrics/wrapper/listener.go index f32efa7d..7ca4c581 100644 --- a/metrics/wrapper/listener.go +++ b/metrics/wrapper/listener.go @@ -2,6 +2,8 @@ package wrapper import ( "net" + + xmetrics "github.com/go-gost/x/metrics" ) type listener struct { @@ -10,10 +12,11 @@ type listener struct { } // WrapListener wraps a net.Listener so that all accepted connections are -// automatically wrapped with WrapConn for metrics tracking. If ln is nil, -// nil is returned. +// automatically wrapped with WrapConn for metrics tracking. If metrics are +// not enabled, ln is returned unchanged to allow splice(2) optimization +// on bare *net.TCPConn. If ln is nil, nil is returned. func WrapListener(service string, ln net.Listener) net.Listener { - if ln == nil { + if ln == nil || !xmetrics.IsEnabled() { return ln } return &listener{