Two identical POST requests in your logs, a few milliseconds apart, same client, same body. The user swears they clicked once, and this time they are right. Nobody double-clicked, nobody pressed back. The browser sent it again by itself.
That is not a bug in Chrome. It is a documented behaviour, it is allowed by the HTTP standard, and it happens in one specific situation that your infrastructure can create without you noticing.
When Chrome resends a request on its own
The logic is in Chromium's net/http/http_network_transaction.cc. When a request fails with a connection error (reset, closed, aborted, or an empty response) Chrome may send it again. The condition is one function:
bool HttpNetworkTransaction::ShouldResendRequest() const {
bool connection_is_proven = stream_->IsConnectionReused();
// NOTE: we resend a request only if we reused a keep-alive connection.
// This automatically prevents an infinite resend loop because we'll run
// out of the cached keep-alive connections eventually.
return connection_is_proven && !HasReceivedResponse();
}
Two conditions, and the method is not one of them. If the request went out on a reused keep-alive connection, and no response had arrived when the connection died, Chrome resends it. GET or POST makes no difference to this check.
The reasoning is sound for the common case. A server closes idle keep-alive connections after a timeout. If the browser picks one of those connections at the same instant the server is closing it, the request never reaches your code, the connection drops, and a resend on a fresh connection is exactly right. The comment above those retry cases describes exactly this race: reusing "a connection that the server is in the process of closing".
What the standard says
RFC 9110, the HTTP semantics standard, is explicit that this is a judgement call. In section 9.2.2: "A client SHOULD NOT automatically retry a request with a non-idempotent method unless it has some means to know that the request semantics are actually idempotent." And then, describing precisely what Chrome does:
Some clients take a riskier approach and attempt to guess when an automatic retry is possible. For example, a client might automatically retry a POST request if the underlying transport connection closed before any part of a response is received, particularly if an idle persistent connection was used.
So the browser is betting that a connection which died before any response means the server never acted on the request. Usually that bet wins.
When the bet loses
It loses when your server did act on the request and then the connection died before a single byte of the response went back. From the browser's side that looks identical to the idle-connection race, so it resends, and your code runs twice.
The situations that produce it are ordinary:
- A deploy or restart that kills a worker after it wrote to the database but before it wrote the response.
- A proxy or load balancer between the browser and your code that drops the client connection without answering, while the backend carries on.
- A slow handler on a connection that something on the path times out.
None of these show up as an error anywhere. The first request succeeded. The second succeeded too. The user sees one response, from the retry.
How to tell, and what to change
In the logs, the signature is two identical non-idempotent requests from the same client, close together, where the first one's connection ended without a response being written. If you can reproduce it with a user's browser, Chrome's chrome://net-export captures a NetLog, and a resend appears there as the event HTTP_TRANSACTION_RESTART_AFTER_ERROR with the error that triggered it.
The fix is not to stop the browser. It is the same as for any duplicate: make the second request harmless. Give each action a key generated once, when the form or page is rendered, send it with the request, and have the server refuse to apply the same key twice. A browser resend carries the same body, so it carries the same key.
And look at what sits between the browser and your code. A component that closes client connections without answering is turning a safe retry into a duplicate.
What the report was missing
"I clicked once and got charged twice" is, in this case, exactly true, and nothing the user did or remembers explains it. The cause lives in a connection that died at the wrong millisecond, which is the one thing no bug report written from memory will ever contain.
Top comments (0)