connection_reuse

command
v1.17.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2026 License: BSD-3-Clause Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL