apache/kafka · warning · InterruptException

Received interrupt while awaiting {operation}

Error message

Received interrupt while awaiting {operation}

What it means

Wrapped as InterruptException (a KafkaException subtype) and thrown from TransactionalRequestResult.await when the thread blocking on a transactional control RPC's CountDownLatch is interrupted via Thread.interrupt() or a shutdown hook. The interrupt is honoured: the await aborts and the producer surfaces it instead of swallowing the status. Because the underlying RPC's outcome is unknown (it may still complete on the broker), the producer's transactional state should be treated as potentially pending; further transactional calls may hit the pending-transition checks.

Source

Thrown at clients/src/main/java/org/apache/kafka/clients/producer/internals/TransactionalRequestResult.java:63

    public void done() {
        this.latch.countDown();
    }

    public void await(long timeout, TimeUnit unit, String expectedTimeoutReason) {
        try {
            boolean success = latch.await(timeout, unit);
            if (!success) {
                throw new TimeoutException("Timeout expired after " + unit.toMillis(timeout) +
                    "ms while awaiting " + operation + ". " + expectedTimeoutReason);
            }

            isAcked = true;
            if (error != null) {
                throw error;
            }
        } catch (InterruptedException e) {
            throw new InterruptException("Received interrupt while awaiting " + operation, e);
        }
    }

    public RuntimeException error() {
        return error;
    }

    public boolean isSuccessful() {
        return isCompleted() && error == null;
    }

    public boolean isCompleted() {
        return latch.getCount() == 0L;
    }

    public boolean isAcked() {
        return isAcked;
    }

View on GitHub (pinned to c31c9215e1)

Solutions

  1. Make shutdown cooperative: drain/close the producer with KafkaProducer.close(Duration) before interrupting worker threads, and don't call shutdownNow() while a transactional operation is in flight.
  2. If interrupted mid-transaction, treat the producer as poisoned: abort or close and recreate; do not assume the transaction completed.
  3. Ensure producer work runs on a thread whose lifecycle is owned by the producer's close path, so interrupts don't hit active transactions.
  4. If using a reactive/task framework, configure it to wait for the producer future instead of cancelling/interrupting.

Example fix

// before
ExecutorService exec = Executors.newSingleThreadExecutor();
Future<?> f = exec.submit(() -> {
    producer.commitTransaction();  // await() blocks
});
exec.shutdownNow();  // interrupts the worker -> InterruptException 296

// after
f.get(30, TimeUnit.SECONDS);  // wait for the commit to finish
exec.shutdown();
exec.awaitTermination(10, TimeUnit.SECONDS);
producer.close(Duration.ofSeconds(10));
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-check the interrupt status before issuing a transactional call so a prior
// interrupt does not surface mid-await:
if (Thread.interrupted()) {
    throw new InterruptedException("Refusing transactional call on an interrupted thread");
}

Try / catch

try {
    producer.commitTransaction();
} catch (org.apache.kafka.common.errors.InterruptException e) {
    // The await was interrupted. Restore the status, decide on shutdown vs retry:
    Thread.currentThread().interrupt();
    if (shuttingDown) { producer.close(Duration.ZERO); throw e; }
    // Otherwise retry — transactional control calls are idempotent.
    producer.commitTransaction();
}

Prevention

When it happens

Trigger: A thread calling initTransactions/beginTransaction/commitTransaction/abortTransaction/sendOffsetsToTransaction is interrupted while blocked on the internal latch — e.g. JVM shutdown hook fires, an ExecutorService.shutdownNow() interrupts the worker, or application code explicitly calls Thread.interrupt() on the producer thread.

Common situations: Container/pod shutdown signal (SIGTERM) triggering a shutdown hook that interrupts producer threads; ExecutorService.shutdownNow() during application teardown; framework timeout (e.g. Spring @Transactional, Lambda deadline) interrupting the worker; explicit cancel of a Future wrapping producer calls; graceful-shutdown logic racing with an in-flight commit.

Related errors


AI-assisted analysis of apache/kafka@c31c9215e1 (2026-08-03). Data as JSON: /data/errors/39b9593f4e5e3910.json. Report an issue: GitHub.