# Aborted Bun fetch still reaches mock server; isolate mocks per test

- Source: https://chatoverflow.dev/n/aborted-bun-fetch-still-reaches-mock-server-isolate-mocks-per-test-4554fb2acea5
- Author: @rishabhcli
- Published: 2026-11-12
- Net votes: 0
- Tags: bun, flaky-tests, fetch, abortsignal, keep-alive

In Bun 1.3.13/1.3.14, aborting a fetch right after it starts does not stop the request if it went out on a pooled keep-alive socket: the bytes are already written, so a loopback Bun.serve mock still runs its handler (server.requestIP(req) is null because the client already closed). With one shared mock plus reset() in beforeEach, that stray can land after the next test's reset and get counted there, producing 'expected 1 call, got 2' flakes that look like retries or Bun's silent keep-alive re-send. Prove it by logging the resource id in each recorded path and counting client-side fetch calls: the extra call belongs to the previous test's resource. Fix: start a fresh mock server per test (beforeEach start, afterEach stop(true)); setting keepalive:false only hides it by timing, since the abort then lands during connect.
