QA GLOSSARY · TERM 4 OF 6
Double-submit bug
A double-submit bug is when sending the same form or order twice, usually with a quick double-click, creates two results instead of one. In this site's QA challenge it is BUG-06, the only one marked Critical: the Place order button stays active while the first order is being sent, so a second click creates a second order and the customer is charged twice.
Why it happens
Sending an order takes a moment. During that moment the page still looks the same and the button can still be clicked. An impatient visitor clicks again, or a tap on a phone registers twice, and the second request leaves before the page has reacted to the first. If the server accepts both, there are two orders.
It is rarely found by testers who click once, politely, and wait. It is found by people who click twice, fast, which is why the challenge's hint is "People click buttons twice. Impatient people click them many times."
The check that catches it
await page.getByRole('button', { name: 'Place order' }).dblclick();
await expect(page.getByTestId('orders')).toHaveCount(1);Two lines: double-click the button, then count the orders. With the bug, the count is 2 and the test fails. It is also a good regression test, because this mistake comes back whenever someone rewrites the form.
How to fix it: two layers
- The page: switch the button off the moment it is used, and show that something is happening. A good button disables itself as soon as it is clicked.
- The server: do not rely on the page. Give each order a unique id when the form opens, send it with the order, and have the server store an order with a given id only once. Then the same order sent twice is one order, even if the second request comes from a retry, a second tab or a slow network.
const [sending, setSending] = useState(false);
async function placeOrder() {
if (sending) return; // a second click while the first is running does nothing
setSending(true);
try {
await fetch("/api/orders", { method: "POST", body: JSON.stringify(order) });
} finally {
setSending(false);
}
}
<button type="button" onClick={placeOrder} disabled={sending}>Place order</button>The second layer has a name: an operation is idempotent when doing it twice has the same effect as doing it once. Making "place order" idempotent is the strongest fix, because it protects against every way a request can be sent twice, not only a double-click.
Other ways the same bug shows up
- Pressing the browser's back button after an order and sending the form again.
- A slow connection and a second tap before anything seems to happen.
- A mobile app or a script that retries a request that actually succeeded.
- Two browser tabs open on the same form.
Questions people ask
Is disabling the button enough?
It stops the common case, and it is the right first step. It does not stop a retry, a second tab or a request sent by something other than the button, so the server should also treat the same order sent twice as one.
What does idempotent mean?
An operation is idempotent when doing it twice has the same effect as doing it once. Setting a value is idempotent. Adding one to a counter is not. An order with a unique id that the server stores only once is.
Why is it marked Critical in the challenge?
Because the cost lands on the customer: they are charged twice. Of the six bugs in the challenge it is the only one with that severity, and the challenge's text says the customer is charged twice.