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.
This commit is contained in:
ginuerzh
2026-06-21 20:34:41 +08:00
parent 9ea10763e4
commit 3f01456480
+6 -3
View File
@@ -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{