An opossum timeout is not a request timeout
Short answer: opossum's timeout option rejects the breaker's promise when the deadline passes. It does not cancel the function it wrapped, because it has no handle on it: no AbortSignal is passed through, and the promise keeps running until the underlying socket closes on its own. So a circuit breaker bounds how long your caller waits, not how long the request lives. If you want the request to stop, the transport (axios timeout, the SDK's own timeout, an AbortSignal) has to stop it, and that transport timeout needs to be at or below the breaker's.
I learned this from a codebase that already had three circuit breakers and looked, from the outside, like it took slow dependencies seriously. It did not.
Three breakers, zero bounded requests
EduScale runs user code through Judge0, calls Gemini for the tutor and code-review features, and uploads to Cloudinary. Each had an opossum breaker in front of it. Every Redis read ended in catch { return null }. The email queue had retry with backoff.
All of that is machinery for a dependency that fails. A rejection arrives, the breaker counts it, the catch block runs.
None of it does anything for a dependency that is merely slow. A socket that is open and quiet produces no rejection, so there is no news for any of that machinery to react to. The audit entry in FINDINGS.md §13 ended up with a line I keep coming back to: a catch cannot catch a hang.
What the breaker actually did
Here is the Judge0 breaker before the fix, in Backend/src/utils/codeExecutor.ts:
const judge0Breaker = new CircuitBreaker(_executeCodeRaw, {
timeout: 15000,
errorThresholdPercentage: 50,
resetTimeout: 30000,
volumeThreshold: 3,
name: 'judge0',
});
_executeCodeRaw did an axios.post to submit the code, then polled axios.get up to ten times with a one-second gap. Neither axios call had a timeout. Opossum's timeout: 15000 was the only deadline in that path.
Picture Judge0 taking 60 seconds to answer. At 15 s, opossum rejects. The caller gets its error, the breaker records a failure. And the axios.post is still sitting there with its socket open, waiting for the 60-second reply, because nothing told it to stop. Opossum cannot: it wrapped a function that returns a promise, and has no reference to the socket inside.
So the breaker bounded caller latency, not socket consumption. Under concurrency, that difference is where the damage is.
Why the fan-out made it worse
The code that calls executeCode runs one submission per test case, all at once. In Backend/src/repositories/challengeRepository.ts:
const results = await Promise.all(
test_cases.map(async (test_case) => {
const result = await executeCode({ code: program, language: data.language, input: test_case.input, ... });
...
})
);
controllers/codeController.ts does the same over the public test cases. The array length comes from the database. There is no concurrency cap.
Now put the two facts together. judge0Breaker is a module-level singleton shared by every user, with volumeThreshold: 3. Say one user submits one challenge with ten test cases while Judge0 is slow. Ten breaker calls fire at once. All ten hit the 15 s timeout: ten failures out of ten, past the volume threshold at 100% failure, so the breaker opens. For everybody. executeCode would return a 503 to every user for the next 30 seconds, and the ten sockets nothing is waiting for would stay open underneath. I worked this out from the config, not from an outage, but nothing in the code stops it.
The part that stung: the same repo already had the right answer one directory over. services/ai/llmService.ts keys its Gemini breaker per API-key fingerprint, with a comment explaining that a shared breaker would let one user's bad key disable the feature for everyone. The reasoning never got carried across to Judge0.
The fix: a rule, not a number
The fix went in as PR #45 (commit 183e12df). The important part is not the timeouts but the rule they follow, at the top of Backend/src/utils/deadlines.ts:
Every call gets a transport-level timeout, and where the call sits inside a breaker, that timeout is at or below the breaker's, so the transport gives up first and the breaker never counts a request it has abandoned as still running.
Every budget now lives in that one file:
/** Judge0's breaker deadline. The transport timeouts below must stay under it. */
export const JUDGE0_BREAKER_TIMEOUT_MS = 15_000;
/** One Judge0 submission POST. */
export const JUDGE0_SUBMIT_TIMEOUT_MS = 8_000;
/** One Judge0 poll GET. */
export const JUDGE0_POLL_TIMEOUT_MS = 5_000;
export const LLM_BREAKER_TIMEOUT_MS = 20_000;
export const LLM_CALL_TIMEOUT_MS = 15_000;
And the axios calls carry them: timeout: JUDGE0_SUBMIT_TIMEOUT_MS on the submit, timeout: JUDGE0_POLL_TIMEOUT_MS on each poll. Axios aborts the socket on timeout, so now the request actually dies before the breaker gives up on it.
Gemini is the same shape with a different mechanism. @google/generative-ai attaches no AbortSignal to its fetch unless you pass a timeout in the SDK's RequestOptions, so llmConfig.ts passes { timeout: LLM_CALL_TIMEOUT_MS } as the second argument to getGenerativeModel. The embedding call in embeddingProvider.ts gets the same treatment, and it is the only Gemini path with no breaker in front of it at all, so that timeout is the only bound it has ever had.
Assert the inequality, not the number
What keeps this from rotting is in Backend/src/tests/services/slowDependency.test.ts:
it('Judge0 submit aborts before the breaker abandons it', () => {
expect(JUDGE0_SUBMIT_TIMEOUT_MS).toBeLessThan(JUDGE0_BREAKER_TIMEOUT_MS);
});
it('a Gemini generate aborts before its per-key breaker abandons it', () => {
expect(LLM_CALL_TIMEOUT_MS).toBeLessThan(LLM_BREAKER_TIMEOUT_MS);
});
It asserts the relationship, not the values. Lower a breaker timeout to 5 s in a hurry and the test fails, instead of silently leaving the transport timeout above it. Same move as in the Redlock post: write the budgets down in one place and test the inequality between them.
When the SDK gives you nothing
supabase-js exposes no timeout and passes no signal to its fetch. That call sits in verifySupabaseToken, in front of every authenticated route and the socket handshake, and it is reached precisely when the JWKS path has already been slow. For that one there is a withDeadline helper in deadlines.ts, a Promise.race against a timer. Its comment is honest about what it is:
* 🔴 `Promise.race` does NOT cancel the work — the same limitation opossum has,
* and the reason this file exists. Use it only where the SDK offers no
* cancellation of its own.
It bounds the caller, same as opossum. It is the best available for that SDK, and the preference order is written next to it: real cancellation first, a race only when there is nothing better.
The Redis half, briefly
The cache client was built with maxRetriesPerRequest: null (required by Redlock) and no commandTimeout. Against a Redis that completes the handshake and then goes quiet, a GET neither resolves nor rejects, so every fail-open catch on that client was unreachable in the one case it existed for.
The test drives this with a fake TCP server that answers INFO and COMMAND and then says nothing. Without commandTimeout, the get has not settled after 1.5 s. With commandTimeout: 300, it rejects with "timed out" and a getCache-shaped function returns null as its catch block intended. The fix is one constructor option in cacheService.ts. The Socket.io pub/sub clients and Bull's connections are built separately and left alone; subscribe and blocking reads are supposed to wait.
What is still open, and why
Timeouts were the part that could be fixed without changing behaviour for correct requests. Two things are still open. The first is written up in docs/SLOW-DEPENDENCIES.md rather than half-done. The second I noticed while writing this post:
- The shared Judge0 breaker behind an unbounded
Promise.all. Both call sites still fan out over the full test-case array with no cap, and the breaker is still one singleton for every user. The transport timeouts stop sockets piling up, but one user's ten slow calls can still trip the shared breaker. The fix is the per-key treatmentllmServicealready has, plus a bound on the fan-out. That changes failure semantics for every user, so it gets its own change and a test for "one user's failures do not open another user's breaker." - The poll loop can outlive the breaker. Each poll is bounded at 5 s, but ten polls with a 1 s gap can run for up to about a minute (10 × (5 s + 1 s)), and the breaker lets go at 15 s. Each socket is now bounded. The loop as a whole is not, and opossum still cannot cancel it.
What to do in your own code
- Open every opossum breaker and look at the function it wraps. If the HTTP or SDK call inside has no timeout of its own, the breaker bounds nothing but your caller's patience.
- Give the call a transport timeout that cancels: axios
timeout, the SDK's request options, anAbortSignal.Promise.raceis a last resort; label it as one. - Keep the transport timeout at or below the breaker's, and assert that inequality in a test.
- Check whether the breaker is shared across users and what sits in front of it. An unbounded
Promise.allbefore a shared breaker with a lowvolumeThresholdturns one slow user into an outage for all. - Test with a dependency that never answers, not one that throws. Injecting an error exercises a path that already worked.
The question I now ask of every breaker, retry and fallback: what delivers the news, and what happens if nothing ever does? The rest of the audit is in EduScale's FINDINGS.md, and the running list of defects from my own projects is on /engineering.