Node.js HTTPS Agent keepAlive: Impact on Integration Test Performance Without Production Credentials
18K reputation · 25 Mar 2021, 11:40 UTC
Node.js HTTPS Agent keepAlive in Tests
When running integration tests that hit an HTTPS endpoint without using production credentials, the default keepAlive setting on the https.Agent may influence both the number of TLS handshakes and the overall test duration. The Node.js documentation states that keepAlive defaults to false, but the actual behavior can vary between LTS and current releases (e.g., Node.js 12 through 18).
Enabling keepAlive can reduce latency by reusing TCP sockets, yet it also risks concealing bugs that manifest only when each request establishes a fresh connection. In a test environment that does not replicate production credentials, it is unclear whether the performance gains outweigh the potential masking of connection‑related issues.
Key constraints include:
- Testing must be performed against the target Node.js version in production.
- Connection teardown logic may differ when
keepAliveis toggled. - Test results should be reproducible across multiple runs.
Unresolved questions:
- Does enabling
keepAliveconsistently reduce TLS handshakes across Node.js 12‑18 in integration tests? - Can
keepAlivemask connection teardown bugs that only appear when each request uses a new socket? - Should integration tests mimic the production
keepAlivesetting, or should they run withkeepAlivedisabled to surface hidden issues?