fix(stream): nil panic when logging error

This commit is contained in:
yusing
2025-09-22 10:27:09 +08:00
parent 62a667758d
commit 6b3bf84148
2 changed files with 15 additions and 2 deletions

View File

@@ -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) {

View File

@@ -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) {