Repository navigation
test(integration): TLS cert hot-reload multi-worker regression test (#586) - #1314
Conversation
…st (#586) Adds integrationTests/security/cert-reload.test.ts which boots Harper with >= 2 HTTP workers, swaps the on-disk server certificate, then asserts that all 40 subsequent TLS handshakes (load-balanced by SO_REUSEPORT across workers) serve the new serial number — catching any per-worker divergence in the table-subscription propagation path. Uses same private key / new serial to isolate cert propagation from key-reload timing. Includes a 2.5s settling sleep after first-observed reload to let all workers' independent 1.5s debounces complete before the hammer assertions run. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request introduces a new integration test (cert-reload.test.ts) to verify that TLS certificate hot-reloads propagate correctly to all HTTP workers, preventing a regression where some workers continue serving stale certificates. The feedback recommends destroying the socket in the error event handler of the TLS connection to prevent potential resource leaks or hanging connections.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| socket.destroy(); | ||
| reject(new Error('TLS connection timed out')); | ||
| }); | ||
| socket.on('error', reject); |
There was a problem hiding this comment.
According to the general rules, when connecting to a TCP port, the socket must be destroyed in all event handlers (connect, timeout, error) to prevent resource leaks and hanging connections. Please ensure that socket.destroy() is called in the error event handler.
socket.on('error', (err) => {
socket.destroy();
reject(err);
});References
- When using
node:netto connect to a TCP port, set an explicit timeout on the socket and ensure that the socket is destroyed in all event handlers (connect,timeout,error) to prevent resource leaks and hanging connections.
|
Reviewed; no blockers found. |
Summary
integrationTests/security/cert-reload.test.tsas a regression guard for TLS certificates not auto-reloaded on worker threads (flipping/stale cert after renewal) #586 (per-worker TLS context divergence on cert renewal)HARPER_SET_CONFIG threads.count)Promise.allSettledand asserts none serve the stale serialHow it catches the bug
The propagation path is: main-thread
fs.watch→ write tosystem.hdb_certificate→ each worker'supdateTLS()subscription callback. If the subscribe notification fails to reach a worker, roughly half of 40 SO_REUSEPORT-balanced connections would return the old serial and the test fails. With the fix in place (table-subscription design), all workers rebuild theirSecureContextand every handshake serves the new serial.Test plan
Promise.allSettledoverPromise.allservername=cert-reload-test.harper.localdoes match our cert specifically viasecureContextsmap (CN-keyed bycreateTLSSelector), not just the default contextCloses #586
🤖 Generated with Claude Code