From 9ccc6c6547c5639489bc7fa7f8588be3be8e599f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Papp?= Date: Thu, 31 Oct 2024 16:48:10 +0100 Subject: [PATCH] Add nil value check --- client/internal/peer/conn.go | 5 +++-- client/internal/peer/nilcheck.go | 23 +++++++++++++++++++++++ client/internal/peer/worker_ice.go | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 client/internal/peer/nilcheck.go diff --git a/client/internal/peer/conn.go b/client/internal/peer/conn.go index e60089cb6..7c99ae15a 100644 --- a/client/internal/peer/conn.go +++ b/client/internal/peer/conn.go @@ -333,10 +333,11 @@ func (conn *Conn) iCEConnectionIsReady(priority ConnPriority, iceConnInfo ICECon ep = wgProxy.EndpointAddr() conn.wgProxyICE = wgProxy } else { - log.Infof("direct iceConnInfo: %v", iceConnInfo.RemoteConn) + conn.log.Infof("direct iceConnInfo: %v", iceConnInfo.RemoteConn) + nilCheck(conn.log, iceConnInfo.RemoteConn) directEp, err := net.ResolveUDPAddr("udp", iceConnInfo.RemoteConn.RemoteAddr().String()) if err != nil { - log.Errorf("failed to resolveUDPaddr") + conn.log.Errorf("failed to resolveUDPaddr") conn.handleConfigurationFailure(err, nil) return } diff --git a/client/internal/peer/nilcheck.go b/client/internal/peer/nilcheck.go new file mode 100644 index 000000000..5d2018ac4 --- /dev/null +++ b/client/internal/peer/nilcheck.go @@ -0,0 +1,23 @@ +package peer + +import ( + "net" + "reflect" + + log "github.com/sirupsen/logrus" +) + +func nilCheck(log *log.Entry, conn net.Conn) { + if conn == nil { + log.Infof("conn is nil") + return + } + + if conn.RemoteAddr() == nil { + log.Infof("conn.RemoteAddr() is nil") + } + + if reflect.ValueOf(conn.RemoteAddr()).IsNil() { + log.Infof("value of conn.RemoteAddr() is nil") + } +} diff --git a/client/internal/peer/worker_ice.go b/client/internal/peer/worker_ice.go index 674fef469..eebcdfd31 100644 --- a/client/internal/peer/worker_ice.go +++ b/client/internal/peer/worker_ice.go @@ -128,6 +128,7 @@ func (w *WorkerICE) OnNewOffer(remoteOfferAnswer *OfferAnswer) { } w.log.Infof("check remoteConn: %v", remoteConn) w.log.Infof("check remoteConn.RemoteAddr: %v", remoteConn.RemoteAddr()) + nilCheck(w.log, remoteConn) w.log.Debugf("agent dial succeeded") pair, err := w.agent.GetSelectedCandidatePair()