Skip to content

Conversation

dannykopping
Copy link
Contributor

@dannykopping dannykopping commented Aug 21, 2025

Closes coder/internal#919

I believe that Error "request failed: Post \"http://127.0.0.1:46685\": net/http: HTTP/1.x transport connection broken: http: CloseIdleConnections called" does not contain "non-2xx response (500)" indicates that the client is closing what it considers to be an idle connection while another goroutine is using it. This is likely caused by another test (running concurrently) shutting down its http server while this test was still running, and both shared a reference to the global http.DefaultTransport. http.Transport maintains a connection pool.

Now we'll be cloning http.DefaultTransport whenever a new webhook handler gets created, ensuring that it maintains its own conn pool.

I've added some defensiveness for the type inference, but it's highly unlikely that will change; in which case let's just revert to previous behaviour and log. I considered copying the panic pattern from tailnet.go, but since this webhook feature is optional, I think it's better to choose a slightly racy implementation than crash the server.

… pool, avoiding conflicts over shared connections

Signed-off-by: Danny Kopping <dannykopping@gmail.com>
@dannykopping dannykopping requested a review from johnstcn August 21, 2025 09:50
@dannykopping dannykopping marked this pull request as ready for review August 21, 2025 09:50
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have some kind of internal "helper" library, perhaps something similar to github.com/hashicorp/go-cleanhttp?

@dannykopping
Copy link
Contributor Author

I like that idea. It'll be quite a sizeable/wide-ranging refactor I'd imagine, and out of scope for this PR, but probably something we should look into in the future.

Thanks for the quick review!

@dannykopping dannykopping merged commit 338e8b5 into main Aug 21, 2025
40 checks passed
@dannykopping dannykopping deleted the dk/flake-919 branch August 21, 2025 10:08
@github-actions github-actions bot locked and limited conversation to collaborators Aug 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flake: TestWebhook/non-200_response
2 participants