From c4798a604ac5dc2dcc3880b941be7b4d4abb980d Mon Sep 17 00:00:00 2001 From: Phi Date: Tue, 8 Aug 2023 12:49:04 +0200 Subject: [PATCH] Make lint happy Address the errcheck lint error by checking the return from conn.Close() --- cmd/lotus-worker/main.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/lotus-worker/main.go b/cmd/lotus-worker/main.go index 7b7409caa..0a5d4efc5 100644 --- a/cmd/lotus-worker/main.go +++ b/cmd/lotus-worker/main.go @@ -779,11 +779,16 @@ func extractRoutableIP(timeout time.Duration) (string, error) { minerIP, _ := maddr.ValueForProtocol(multiaddr.P_IP6) minerPort, _ := maddr.ValueForProtocol(multiaddr.P_TCP) - conn, err := net.DialTimeout("tcp", "["+minerIP+"]:"+minerPort, timeout) // Enclose IPv6 address in brackets + conn, err := net.DialTimeout("tcp", minerIP+":"+minerPort, timeout) if err != nil { return "", err } - defer conn.Close() + + defer func() { + if cerr := conn.Close(); cerr != nil { + log.Errorf("Error closing connection: %v", cerr) + } + }() localAddr := conn.LocalAddr().(*net.TCPAddr) return localAddr.IP.String(), nil