diff --git a/prober/http.go b/prober/http.go index d79e8e1c..c21b8a6f 100644 --- a/prober/http.go +++ b/prober/http.go @@ -353,14 +353,27 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr } } } - client, err := pconfig.NewClientFromConfig(httpClientConfig, "http_probe", pconfig.WithKeepAlivesDisabled()) + dialWithLinger := func(ctx context.Context, network, addr string) (net.Conn, error) { + d := &net.Dialer{} + conn, err := d.DialContext(ctx, network, addr) + if err != nil { + return nil, err + } + tcpConn, ok := conn.(*net.TCPConn) + if ok { + tcpConn.SetLinger(0) + return tcpConn, nil + } + return conn, nil + } + client, err := pconfig.NewClientFromConfig(httpClientConfig, "http_probe", pconfig.WithKeepAlivesDisabled(), pconfig.WithDialContextFunc(dialWithLinger)) if err != nil { level.Error(logger).Log("msg", "Error generating HTTP client", "err", err) return false } httpClientConfig.TLSConfig.ServerName = "" - noServerName, err := pconfig.NewRoundTripperFromConfig(httpClientConfig, "http_probe", pconfig.WithKeepAlivesDisabled()) + noServerName, err := pconfig.NewRoundTripperFromConfig(httpClientConfig, "http_probe", pconfig.WithKeepAlivesDisabled(), pconfig.WithDialContextFunc(dialWithLinger)) if err != nil { level.Error(logger).Log("msg", "Error generating HTTP client without ServerName", "err", err) return false diff --git a/prober/tcp.go b/prober/tcp.go index de960db2..aabca20f 100644 --- a/prober/tcp.go +++ b/prober/tcp.go @@ -114,6 +114,9 @@ func ProbeTCP(ctx context.Context, target string, module config.Module, registry level.Error(logger).Log("msg", "Error dialing TCP", "err", err) return false } + if tcpConn, ok := conn.(*net.TCPConn); ok { + tcpConn.SetLinger(0) + } defer conn.Close() level.Info(logger).Log("msg", "Successfully dialed")