@cryptotaxi247 / netdata-1 / commits / 9af7592fd

go.d: socket package: don't set client on connect() err (#17283)

Ilya Mashchenko committed Mar 28, 2024 at 15:31 UTC 9af7592fdbbf3ab7387c77accd2f9c93a8eee719
1 file changed +13 -4
src/go/collectors/go.d.plugin/pkg/socket/client.go
+13 -4
@@ -31,16 +31,25 @@ type Socket struct {
31 // If the address is a domain name it will also perform the DNS resolution.
32 // Address like :80 will attempt to connect to the localhost.
33 // The config timeout and TLS config will be used.
34 -func (s *Socket) Connect() (err error) {
34 +func (s *Socket) Connect() error {
35 network, address := networkType(s.Address)
36 + var conn net.Conn
37 + var err error
38 +
39 if s.TLSConf == nil {
37 - s.conn, err = net.DialTimeout(network, address, s.ConnectTimeout)
40 + conn, err = net.DialTimeout(network, address, s.ConnectTimeout)
41 } else {
42 var d net.Dialer
43 d.Timeout = s.ConnectTimeout
41 - s.conn, err = tls.DialWithDialer(&d, network, address, s.TLSConf)
44 + conn, err = tls.DialWithDialer(&d, network, address, s.TLSConf)
45 }
43 - return err
46 + if err != nil {
47 + return err
48 + }
49 +
50 + s.conn = conn
51 +
52 + return nil
53 }
54
55 // Disconnect closes the connection.