ECANCELED
Linux / POSIXERRORCommonProcessHIGH confidence

Operation Canceled

Production Risk

Expected when using operation cancellation; handle like a retry condition.

What this means

ECANCELED (errno 125) is returned when an asynchronous operation was explicitly canceled, either via aio_cancel() or io_cancel(). It indicates the operation was stopped before completion — not that it failed.

Why it happens
  1. 1aio_cancel() successfully canceled a pending AIO request
  2. 2io_cancel() canceled a Linux io_uring or libaio operation
  3. 3pthread_cancel() canceled a thread that was in a cancellation point
How to reproduce

aio_cancel() cancels a pending read.

trigger — this will error
trigger — this will error
struct aiocb cb = { .aio_fildes = fd, ... };
aio_read(&cb);
// Cancel before it completes
aio_cancel(fd, &cb);
// aio_error(&cb) returns ECANCELED

expected output

aio_error: Operation canceled (ECANCELED)

Fix

Check cancellation status and handle appropriately

WHEN When using AIO or io_uring with cancellation

Check cancellation status and handle appropriately
int err = aio_error(&cb);
if (err == ECANCELED) {
  // Operation was canceled — retry if needed
  aio_read(&cb);
} else if (err == 0) {
  // Completed — read result with aio_return()
  ssize_t n = aio_return(&cb);
}

Why this works

ECANCELED means the operation was intentionally stopped; retry or skip as the application logic requires.

What not to do

Treat ECANCELED as a permanent failure

The operation was canceled, not failed; it can be safely retried.

Sources

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Linux / POSIX errors