From 6b3bf841482e5e00be7def129cd7f58a84d9fdca Mon Sep 17 00:00:00 2001 From: yusing Date: Mon, 22 Sep 2025 10:27:09 +0800 Subject: [PATCH] fix(stream): nil panic when logging error --- internal/route/stream/tcp_tcp.go | 9 ++++++++- internal/route/stream/udp_udp.go | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/internal/route/stream/tcp_tcp.go b/internal/route/stream/tcp_tcp.go index 66c424d3..a00a7385 100644 --- a/internal/route/stream/tcp_tcp.go +++ b/internal/route/stream/tcp_tcp.go @@ -70,7 +70,14 @@ func (s *TCPTCPStream) LocalAddr() net.Addr { } func (s *TCPTCPStream) MarshalZerologObject(e *zerolog.Event) { - e.Str("protocol", "tcp-tcp").Str("listen", s.listener.Addr().String()).Str("dst", s.dst.String()) + e.Str("protocol", "tcp-tcp") + + if s.listener != nil { + e.Str("listen", s.listener.Addr().String()) + } + if s.dst != nil { + e.Str("dst", s.dst.String()) + } } func (s *TCPTCPStream) listen(ctx context.Context) { diff --git a/internal/route/stream/udp_udp.go b/internal/route/stream/udp_udp.go index 393e4a7d..c10cf3f2 100644 --- a/internal/route/stream/udp_udp.go +++ b/internal/route/stream/udp_udp.go @@ -113,7 +113,13 @@ func (s *UDPUDPStream) LocalAddr() net.Addr { } func (s *UDPUDPStream) MarshalZerologObject(e *zerolog.Event) { - e.Str("protocol", "udp-udp").Str("name", s.name).Str("dst", s.dst.String()) + e.Str("protocol", "udp-udp") + if s.name != "" { + e.Str("name", s.name) + } + if s.dst != nil { + e.Str("dst", s.dst.String()) + } } func (s *UDPUDPStream) listen(ctx context.Context) {