Documentation
¶
Overview ¶
Package main verifies that a client reuses one TCP connection for subsequent requests to the same host, instead of dialing and handshaking again every time. That is the behaviour questioned in https://github.com/bogdanfinn/tls-client/issues/112.
The check does not rely on timings. It counts the actual TCP dials through a wrapping dialer and cross-checks that against httptrace, which reports per request whether the connection came out of the idle pool. The local port of every connection is recorded too, so "same connection" is shown rather than inferred.
The connection is reused, including with the exact options from the issue. Against the default target every scenario here dials once for all requests, and the requests after the first drop from roughly 400ms to 100ms, which is the TLS handshake no longer happening.
Why the issue reports otherwise: its target is https://tls.peet.ws, and that host does not keep the connection alive. It sends a stray CRLF pair on the idle connection after a response, so the client has to discard it. Go's own net/http behaves identically against that host and logs "Unsolicited response received on idle HTTP channel", so it is the server, not the client. Pass -url https://tls.peet.ws/api/tls to see it.
Run:
go run ./example/connection_reuse go run ./example/connection_reuse -scenario h1 -requests 5 go run ./example/connection_reuse -url https://tls.peet.ws/api/tls