Skip to content

test: Add source audits for http.Transport idle limits and temp-file renames without Sync #1554

Closed

Description

@huang195

Problem

Two of the audit's bugs come from a pattern that repeats across files. Fixing each copy by hand leaves the next copy to be written. A source-scanning test would catch every new one, like core/listener/parity/dispatch_audit_test.go already does for request-context dispatches.

1. http.Transport without MaxIdleConnsPerHost

Without it, Go keeps 2 idle connections per host. With an HTTP/1.1-only gateway such as LiteLLM, extra concurrent requests then pay a new TCP+TLS handshake each (#1546: 10 concurrent callers opened 36–45 connections instead of 10).

A prototype go/ast scan of main (43cf553) finds all 3 http.Transport literals without it:

  • core/listener/forwardproxy/server.go:209
  • core/tlsbridge/upstream.go:28
  • core/plugins/inferencerouter/routerconfig/models.go:134. This one is a one-shot model-list fetch, so it can be exempt with a reason.

2. Temp-file-and-rename without Sync

Renaming a temp file over the real one without f.Sync() first can leave the destination empty after a power loss (#1547). The plugin store and the session archive do it right; the same scan finds 12 functions that do not:

Function What it writes Losing it means
core/tlsbridge/ca.go:286 atomicWriteFile bridge CA key + cert every agent's trust of the CA breaks
cmd/agentop/cmd_claudecode.go:954 writeSettings the user's ~/.claude/settings.json user config lost
cmd/agentop/cmd_config_migrate.go:226 replaceConfig ~/.cortex/config.yaml proxy will not start
cmd/agentop/userconfig.go:102 saveUserConfig agentop settings user config lost
cmd/agentop/cmd_bob.go:951 bobWriteKeys, cmd_codex.go:464 write agent config files user config lost
core/observe/claude/harvest.go:1999 SaveMetadata session titles #1547
core/spiffe/mirror.go:24 atomicWrite SVID mirror rewritten on next rotation
cmd/agentop/cmd_script.go:455 writeAtomic installed script plugin reinstall
core/cost/pricing/pricelist/pricelist.go:162 save price-list cache re-downloaded
cmd/agentop/cmd_service_platform.go:789 writeProxyStamp binary checksum stamp recomputed
core/plugins/script/sdk.go:18 installSDK SDK file rewritten

The scan matches by name inside one function (os.Rename, plus CreateTemp/WriteFile, minus any .Sync()), so each hit needs a look. The last four look safe to exempt, since the file is rebuilt or rewritten anyway.

Proposed tests

  • Two go/ast audits in the style of dispatch_audit_test.go. One walks the non-test .go files of core and cmd; the other does the same for the rename pattern.
  • Each failure names file:line and what to add.
  • Each test keeps an allowlist that gives a reason per entry, so an exemption is a decision someone made, not silence.

How to land

Both tests need no fix to land: today's hits go into the allowlist, each pointing at #1546 or #1547, and leave it as those issues are fixed. From then on, a new transport or atomic write fails CI unless it is done right or allowlisted with a reason.


Found while checking why the bugs from an experiment-driven audit (#1541–#1547) got past CI. Grounded on main at 43cf553.

Assisted-By: Claude (Anthropic AI) [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementgo

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions