Sitelet https://github.com/moby/moby/pull/53438
Skip to content

daemon/logger/awslogs: avoid user-agent test race - #53438

Open
JasonColapietro wants to merge 1 commit into
moby:masterfrom
JasonColapietro:53273-fix-awslogs-test-race
Open

daemon/logger/awslogs: avoid user-agent test race#53438
JasonColapietro wants to merge 1 commit into
moby:masterfrom
JasonColapietro:53273-fix-awslogs-test-race

Conversation

@JasonColapietro

Copy link
Copy Markdown

Summary

Make the AWS logs user-agent unit test inspect the SDK-built request through an injected synchronous HTTP client.

The real net/http transport serializes request headers on a separate goroutine, which can race with AWS middleware header mutation — the failure seen on Windows in TestNewAWSLogsClientUserAgentHandler, where net/http.(*persistConn).writeLoop was reading the request header map in Header.sortedKeyValues while the middleware wrote to it.

The test only needs to verify the final User-Agent header, so replacing the httptest.Server with config.WithHTTPClient and a smithyhttp.ClientDoFunc inspects the actual SDK-built request synchronously and avoids the transport concurrency entirely. The AWS middleware path under test is unchanged.

Scope

One test file changes. No production code or behavior is touched.

Testing

  • go test -race -run '^TestNewAWSLogsClientUserAgentHandler$' -count=100 ./daemon/logger/awslogs — ok
  • go test -race ./daemon/logger/awslogs — ok
  • GOOS=windows GOARCH=amd64 go test -c ./daemon/logger/awslogs — ok
  • git diff --check — clean

Risks

The revised test no longer exercises Go's real HTTP transport. That transport is outside the behavior under test; the AWS middleware still builds the actual request that the injected client inspects.

Created with: Codex

Signed-off-by: Jason Colapietro <jasoncola1@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky test: TestNewAWSLogsClientUserAgentHandler (race: concurrent map read and map write)

1 participant