Field notes · Engineering

Why a queue error crashed requests that never touched the queue

A bug in a message queue library sent its errors to whichever request was borrowing the thread, so unrelated requests failed without a trace.

Ben Morrall · Software · 2 min read · 22 May 2026 · Discuss in Slack


You wouldn’t believe the bug I fixed this week. Fair warning: this one gets technical.

The problem

We’d been getting random failures. Some requests never reached the message queue, and nothing told us why.

One part of the setup made no sense. A request put a message on a queue, then waited on a separate thread for a ping to confirm it arrived. That work went onto a background worker queue, only to be put on another queue. There was no reason for the extra hop, so I moved the code into the HTTP request handler itself. If the queue timed out, the caller could at least report it.

At first it worked. Requests that had taken 30 seconds or more finished in 1 ms, and availability was back.

Then it hit the fan. Errors started showing up that didn’t match where they came from. A basic endpoint that reads a record from the database and formats it threw queue errors. Other connections dropped at random, without a trace. The only response with a stack trace held nothing but a message about the queue.

What we found

I pointed Claude at the queue library and asked it to take a gander. That’s where we found it.

Remember the separate thread that waits for the ping? When the ping failed, I expected the library to flag the connection as broken, so I could reconnect and try again.

Instead, the library has a bug. When it spawns the ping thread, it remembers which thread spawned it, and sends any error back to that thread.

That breaks with a connection pool, which is what we use. Connections to the queue are expensive to open, so the pool opens them once and shares them around the system. A request borrows a connection instead of opening and closing one for a single message. It also means a connection doesn’t always run on the thread that made it, and that thread may since have moved on to other work.

We were also having network trouble with the queue service. So we’d send a message, the library would spawn a thread to wait for the ping, and the ping wouldn’t arrive. The error went back to the calling thread. By then that thread had moved on, say to answering a request for a database record, and it got unceremoniously nuked from orbit. Usually that left no error report and no breadcrumbs. If we were lucky enough to be inside error reporting at the time, we got an error that didn’t match its source.

The fix

I tied the error to the connection instead of the thread, using a mutex: a lock that lets only one thread change something at a time. Now the next request to use a broken connection fails. Recovering from that is easy: drop the bad connection, grab a fresh one from the pool, and retry.

We no longer see the error the moment it happens. But “the moment it happens” used to mean some poor unrelated thread getting blown up, so I can live with that.

What’s next

The network problems with the queue service still need fixing. In the meantime, the service is ticking along without random crashes.

Esc