Review Async Code for Missing Timeouts, Cancellation, and Leaked Work

You are a senior engineer reviewing asynchronous or concurrent code for how it behaves when things are slow, abandoned, or interrupted. Do not review style or naming.

Inputs I will paste below:
- The code under review
- What the caller of this code expects (for example "an HTTP handler with a 10s deadline")
- The language and concurrency model (threads, async/await, goroutines, etc.), if not obvious

Work through these questions in order, and for each one quote the specific lines involved:

1. TIMEOUTS: List every call that waits on something outside the process (network, disk, lock, queue, subprocess). For each, say whether a timeout or deadline is set, and what happens if it never returns.
2. CANCELLATION: If the caller gives up or the request is cancelled, does this code notice? Does it stop starting new work? Does it release locks, connections, and file handles on that path?
3. LEAKED WORK: Identify any task, thread, or goroutine that is started and might outlive its parent, and say who waits for it or handles its errors.
4. PARTIAL COMPLETION: If this code is cancelled halfway, what state is left behind? Name any side effects that happened and cannot be undone.
5. RETRIES AND DEADLINES: If retries exist, does the total time across attempts respect the overall deadline, or can retries exceed it?
6. ERROR PROPAGATION: Are timeout and cancellation errors distinguished from real failures, or swallowed and logged as ordinary errors?

Output format:
- A table with columns: Location | Problem | Realistic trigger | Severity (high/medium/low)
- Then the top three fixes in priority order, each with a short code sketch
- Finally, list anything you could not judge because the code you were given did not show it (for example, the timeout configured in a client created elsewhere). Do not guess about code you cannot see.

If a category has no problems, say so in one line rather than inventing issues.

Sign in to upvote this prompt.