How to Handle Keep-Alive Connections in Go

Web
Go automatically reuses HTTP connections for performance; disable this by setting Transport.DisableKeepAlives to true.

Go handles HTTP keep-alive connections automatically by default, reusing TCP connections for multiple requests to improve performance. To disable this behavior and force a new connection for every request, set DisableKeepAlives to true in your http.Transport configuration.

client := &http.Client{
	Transport: &http.Transport{
		DisableKeepAlives: true,
	},
}

If you are experiencing performance issues due to excessive idle connections, ensure Transport.MaxIdleConns is set to a reasonable limit rather than 0.