python
9 minAsync Python Cancellation and Timeouts: Stop Work Without Leaking It
Understand task cancellation, timeout scopes, cleanup, and the failure modes that leave background work running.
Loading page...
python
9 minUnderstand task cancellation, timeout scopes, cleanup, and the failure modes that leave background work running.
Q&A
Q&AFresh timeouts at each stage multiply the total wait.
Measure elapsed time locally with nanoTime and give each stage only the shared budget remaining. Expiry stops admission of more work; it does not prove a remote write was cancelled.
python
8 minA practical guide to request concurrency, connection pools, timeouts, and overload behavior in async Python APIs.
Q&A
Q&APacket direction and handshake behavior help locate whether loss occurs before or after the destination.
Capture narrowly at the client and, if possible, server. A SYN leaving without a reply suggests routing or filtering; a reset indicates an active rejection or no listener; a completed handshake moves investigation toward TLS or the application protocol. Packet captures can expose sensitive metadata or payloads, so limit capture scope and protect files.
Q&A
Q&AEqual timestamps otherwise make continuation skip or repeat peers.
Carry the full ordering tuple, such as created_at and ID, and match its direction in the continuation predicate. Stable continuation still does not freeze membership across requests.
java
6 minSeparate elapsed time from civil time and carry a shrinking deadline through a request.
Q&A
Q&ABound concurrency and queue depth at the scarce resource, and enforce an end-to-end deadline.
Use bounded connection pools, semaphores or worker queues, request deadlines, and deliberate overload responses. Local limits must account for replica count because each replica has its own pool. Avoid unbounded in-memory tasks and retries that amplify load during an incident.
Q&A
Q&ARelease owned resources in cleanup and normally propagate cancellation after cleanup.
Cancellation is delivered at an await point. Use finally blocks or async context managers to close resources, then re-raise CancelledError unless there is a deliberate reason to suppress it. A blocking synchronous call may not respond promptly, so keep the event loop cooperative and bound background work.