Skip to content

Resend provider requests that were never written - #1779

Open
kevmo314 wants to merge 1 commit into
mainfrom
claude/eager-dijkstra-hdrup8
Open

kevmo314 wants to merge 1 commit into
mainfrom
claude/eager-dijkstra-hdrup8

Conversation

@kevmo314

Copy link
Copy Markdown
Contributor

Problem

Error group CJ3zuIS42bCqcg:

HTTP POST /send returned 500: provider transport failure   (latency 157ms)

clients.Do returns provider transport failure when the HTTP client gets no response at all. Go's transport replays a failed request only on a reused connection, and never replays a POST otherwise. So a connection that fails during setup (dial, TLS handshake, reset before anything is sent) surfaces as an error, even though Twitch never saw the chat message.

I checked whether the cause was idle connections: a live keep-alive connection to api.twitch.tv stayed open 240s before closing. That's longer than Go's 90s idle timeout, so Twitch closing stale connections isn't it, and this PR doesn't tune timeouts.

Fix

clients.Do now attaches an httptrace.ClientTrace to each request and resends once, whatever the method, only on positive evidence that the request never left:

  • Resend: the transport started getting a connection (GetConn) and wrote nothing (no WroteHeaders, no WroteRequest). That request had no effect.
  • No resend: anything that may have been written. A chat message can't be posted twice.
  • No resend: transports that report no trace hooks, such as the test fakes. These stay ambiguous.

The trace flags are read only after client.Do returns. On error, Go's transport waits for its write loop to finish before returning (mapRoundTripError waits on writeLoopDone), so a late write is always visible. A write that fails partway can't deliver a complete request.

Tests

  • TestDoResendsRequestsThatWereNeverWritten runs a TLS server that drops the first connection during the handshake. On main the POST fails with provider transport failure and the server receives nothing. Here it succeeds, and the server receives the request exactly once.
  • TestDoDoesNotResendWrittenRequests has the server receive the POST and then drop the connection without answering. It fails as before, and the server still receives it only once.
  • TestCleanupRetainsUncertaintyUntilDeleteIsSettled, whose fake transport models a lost DELETE response, caught my first draft (which treated "no trace hooks fired" as "unsent"). It now passes unchanged.

go test -race passes for clients, cmd, catalog, jobs, publichttp, subscriptions, webhook, provider and handler.


Generated by Claude Code

POST /send returned 500 "provider transport failure" after 157ms: the
Twitch request failed at the connection, before any response. Go's
transport only replays such failures on reused connections, and never
replays a POST otherwise, so a connection that failed during setup
surfaced as an error although Twitch never saw the message.

clients.Do now traces each request. When the transport began getting a
connection and wrote nothing (no headers, no request), the request had
no effect, so it is resent once whatever its method. A request that may
have been written stays an error, so a chat message is never posted
twice, and a transport that reports neither is treated as ambiguous.

(Twitch keeps idle connections for 240s, longer than Go's 90s idle
timeout, so a server-closed idle connection isn't the cause.)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EzdqAWrbTMdtJutmK41coy

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants