@@ -80,8 +80,10 @@ func dialTCP(ctx context.Context, target string, module config.Module, registry
80
80
// via tlsConfig to enable hostname verification.
81
81
tlsConfig .ServerName = targetAddress
82
82
}
83
- timeoutDeadline , _ := ctx .Deadline ()
84
- dialer .Deadline = timeoutDeadline
83
+
84
+ if timeoutDeadline , ok := ctx .Deadline (); ok {
85
+ dialer .Deadline = timeoutDeadline
86
+ }
85
87
86
88
logger .Info ("Dialing TCP with TLS" )
87
89
return tls .DialWithDialer (dialer , dialProtocol , dialTarget , tlsConfig )
@@ -124,7 +126,6 @@ func ProbeTCP(ctx context.Context, target string, module config.Module, registry
124
126
Help : "Indicates if probe failed due to regex" ,
125
127
})
126
128
registry .MustRegister (probeFailedDueToRegex )
127
- deadline , _ := ctx .Deadline ()
128
129
129
130
conn , err := dialTCP (ctx , target , module , registry , logger )
130
131
if err != nil {
@@ -134,13 +135,13 @@ func ProbeTCP(ctx context.Context, target string, module config.Module, registry
134
135
defer conn .Close ()
135
136
logger .Info ("Successfully dialed" )
136
137
137
- // Set a deadline to prevent the following code from blocking forever.
138
- // If a deadline cannot be set, better fail the probe by returning an error
139
- // now rather than blocking forever.
140
- if err := conn .SetDeadline (deadline ); err != nil {
141
- logger .Error ("Error setting deadline" , "err" , err )
142
- return false
138
+ if deadline , ok := ctx .Deadline (); ok {
139
+ if err := conn .SetDeadline (deadline ); err != nil {
140
+ logger .Error ("Error setting deadline" , "err" , err )
141
+ return false
142
+ }
143
143
}
144
+
144
145
if module .TCP .TLS {
145
146
state := conn .(* tls.Conn ).ConnectionState ()
146
147
registry .MustRegister (probeSSLEarliestCertExpiry , probeTLSVersion , probeSSLLastChainExpiryTimestampSeconds , probeSSLLastInformation )
0 commit comments