apache/hadoop · warning · InterruptedIOException

Interrupted while waiting for IO on channel {}. Total timeou

Error message

Interrupted while waiting for IO on channel {}. Total timeout mills is {}, {} millis timeout left.

What it means

SelectorPool.select(long timeout) re-arms when select() spuriously returns 0 early, decrementing timeoutLeft each round, and after each round checks Thread.currentThread().isInterrupted(). An interrupt while parked is converted to InterruptedIOException carrying the total timeout and remaining budget — turning thread interruption into an IO-level cancellation signal for callers of doIO/connect/waitForIO.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/SocketIOWithTimeout.java:350

          long start = (timeout == 0) ? 0 : Time.now();

          key = channel.register(info.selector, ops);
          ret = info.selector.select(timeoutLeft);
          
          if (ret != 0) {
            return ret;
          }
          
          /* Sometimes select() returns 0 much before timeout for 
           * unknown reasons. So select again if required.
           */
          if (timeout > 0) {
            timeoutLeft -= Time.now() - start;
            timeoutLeft = Math.max(0, timeoutLeft);
          }
          
          if (Thread.currentThread().isInterrupted()) {
            throw new InterruptedIOException("Interrupted while waiting for "
                + "IO on channel " + channel + ". Total timeout mills is "
                + timeout + ", " + timeoutLeft + " millis timeout left.");
          }

          if (timeoutLeft == 0) {
            return 0;
          }
        }
      } finally {
        if (key != null) {
          key.cancel();
        }
        
        //clear the canceled key.
        try {
          info.selector.selectNow();
        } catch (IOException e) {
          LOG.info("Unexpected Exception while clearing selector : ", e);

View on GitHub (pinned to 2add963021)

Solutions

  1. Treat InterruptedIOException as cancellation: abort the operation and release the channel/stream; do not blindly retry
  2. Interrupt IO threads only as a last resort; prefer closing the channel, which unblocks the IO deterministically
  3. If you catch it and swallow it, restore the flag with Thread.currentThread().interrupt() so upstream logic still sees the interrupt

Example fix

// before
executor.shutdownNow(); // interrupts IO threads mid-read -> opaque failure

// after
executor.shutdown();
if (!executor.awaitTermination(30, TimeUnit.SECONDS)) {
  channel.close(); // unblocks IO deterministically
  executor.shutdownNow();
}
Defensive patterns

Strategy: try-catch

Validate before calling

// no pre-check can prevent a concurrent interrupt; make cancellation cooperative
if (Thread.currentThread().isInterrupted()) throw new InterruptedIOException();

Try / catch

catch (InterruptedIOException e) {
  Thread.currentThread().interrupt(); // preserve the interrupt status
  abortTransferAndRelease();         // treat as cancellation, not a retryable error
}

Prevention

When it happens

Trigger: Another thread interrupts the caller while it is blocked in a timed SocketIOWithTimeout read/write/connect: RPC call cancellation, ExecutorService.shutdownNow(), test teardown interrupting IO threads, or application shutdown hooks.

Common situations: Hadoop IPC clients cancelling calls; thread pools shutting down during block transfers; integration tests that interrupt worker threads instead of closing channels; frameworks that use interrupt as a general control signal.

Understand the failure class

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/acc4ab01247ec90d. Report an issue: GitHub.