File descriptor leak debugging lab. The shipping-quote service works perfectly, until it can't open a single socket. A restart fixes it, for a while.
Practice debugging a file descriptor leak in a live, broken production system in your browser, with Go and HTTP. Find the root cause in the logs, terminal and code, fix it, and a load test checks that the fix holds under real traffic.
> Go only. This stack is about how Go's HTTP client manages its connections, so it ships in Go alone.
1. The Incident Context
The shipping-quote service asks three carrier APIs for a price on every cart. After about an hour of uptime it starts failing every request with too many open files. A restart fixes it right away. On-call has been restarting it by hand all night.
2. Observed Symptoms & Metrics
- Affected Endpoints / Components:
GET /quotes?zip={zip}&weight={kg} on the shipping-quote service. It calls three mock carriers: carrier-a on localhost:9001, carrier-b on localhost:9002, carrier-c on localhost:9003.
- Behavior: Latency stays flat at about 30 ms until the process reaches its limit of 1,024 open file descriptors. After that, the service can't open new sockets: carriers drop out of the quotes even though they are up, and some requests fail outright. In the lab, traffic is sped up so this happens within about 90 seconds of a restart.
- Error Rate: 0% before the limit. After it, most responses are missing at least one healthy carrier, and the logs fill with
too many open files.
- System Metrics: The number of open file descriptors in the app process climbs steadily and never comes down, even between bursts of traffic. Almost all of them are sockets. Carrier-b answers
503 to about 30% of calls, and the count seems to climb faster when it does.
3. Application Logs
2026/10/12 03:00:00 shipping-quote service listening on :8080
2026/10/12 03:01:27 carrier-b: status 503, skipping
2026/10/12 03:01:31 http: Accept error: accept tcp [::]:8080: accept4: too many open files; retrying in 5ms
2026/10/12 03:01:31 carrier-a: Get "http://localhost:9001/rates?weight=2&zip=10001": dial tcp 127.0.0.1:9001: socket: too many open files, skipping
# ls -l /proc/$(pgrep -x app)/fd | grep -c socket
1012
# curl 'localhost:8080/quotes?zip=10001&weight=2'
{"quotes":[{"carrier":"carrier-a","priceCents":765,"days":3},{"carrier":"carrier-c","priceCents":873,"days":2}],"weightKg":2,"zip":"10001"}
4. Your Objective
Step into the live environment while synthetic traffic is running, find the root cause, and patch the code.
To clear this stack, your fix must pass these checks under a 90-second load test at 40 req/s, with carrier-b answering 503 to 30% of calls:
- Error Rate: Fewer than 1% of requests fail (
http_errors < 1%).
- Stability: The app's open file descriptors stay below 200 for the whole test (
max_open_fds < 200).
- Data Integrity: Each response lists every carrier that answered 200 with its correct quote, and leaves out carriers that failed (
data_integrity).
Toolbox: curl 'localhost:8080/quotes?zip=10001&weight=2', ls /proc/$(pgrep -x app)/fd | wc -l, ls -l /proc/$(pgrep -x app)/fd | grep -c socket, curl localhost:9002/stats (each carrier has one). Save a file in the editor to rebuild and restart the app. Click Verify when you think it's fixed.
Terms in this lab: FD (file descriptor: a handle the OS gives for every open file and every open socket; each process has a limit), socket, 503, req/s.
You can browse stacks without an account. To run labs you sign in with your email or Google account. BustedStack uses your email address to
sign you in, and your name and profile picture to show your account and pre-fill certificates. We never access your Gmail, contacts or Drive,
sell your data or run ad trackers.
This site needs JavaScript to run labs.