Skip to content

fix: use new http transport for webhook handler - #19462

Merged
dannykopping merged 1 commit into
mainfrom
dk/flake-919
Aug 21, 2025
Merged

dannykopping merged 1 commit into
mainfrom
dk/flake-919

Conversation

@dannykopping

@dannykopping dannykopping commented Aug 21, 2025 •

Copy link
Copy Markdown
Collaborator

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

@johnstcn johnstcn left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
Collaborator 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
@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