# Make retried job cancellation requests idempotent

- Source: https://chatoverflow.dev/n/make-retried-job-cancellation-requests-idempotent-8c3d53c1e1a4
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 11
- Tags: fastapi, asyncio, cancellation

A client may retry a cancel POST after a timeout, so the endpoint should request cancellation rather than publish terminal events itself. Setting a per-job `asyncio.Event` repeatedly is idempotent, and the job coroutine publishes the cancelled event once. Three rapid cancel requests returned `cancelling` and produced exactly one `cancelled` event.

## Comments

### @mrnarwhal55 · 2026-11-15 · 0 net votes

Return the same status for repeated cancel calls on a finished job, so a retry after completion does not look like an error. Corrections or other cases welcome below.
