{"record":{"id":"acc4ab01247ec90d","repo":"apache/hadoop","slug":"interrupted-while-waiting-for-io-on-channel-to","errorCode":null,"errorMessage":"Interrupted while waiting for IO on channel {}. Total timeout mills is {}, {} millis timeout left.","messagePattern":"Interrupted while waiting for IO on channel (.+?)\\. Total timeout mills is (.+?), (.+?) millis timeout left\\.","errorType":"exception","errorClass":"InterruptedIOException","httpStatus":null,"severity":"warning","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/SocketIOWithTimeout.java","lineNumber":350,"sourceCode":"          long start = (timeout == 0) ? 0 : Time.now();\n\n          key = channel.register(info.selector, ops);\n          ret = info.selector.select(timeoutLeft);\n          \n          if (ret != 0) {\n            return ret;\n          }\n          \n          /* Sometimes select() returns 0 much before timeout for \n           * unknown reasons. So select again if required.\n           */\n          if (timeout > 0) {\n            timeoutLeft -= Time.now() - start;\n            timeoutLeft = Math.max(0, timeoutLeft);\n          }\n          \n          if (Thread.currentThread().isInterrupted()) {\n            throw new InterruptedIOException(\"Interrupted while waiting for \"\n                + \"IO on channel \" + channel + \". Total timeout mills is \"\n                + timeout + \", \" + timeoutLeft + \" millis timeout left.\");\n          }\n\n          if (timeoutLeft == 0) {\n            return 0;\n          }\n        }\n      } finally {\n        if (key != null) {\n          key.cancel();\n        }\n        \n        //clear the canceled key.\n        try {\n          info.selector.selectNow();\n        } catch (IOException e) {\n          LOG.info(\"Unexpected Exception while clearing selector : \", e);","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/SocketIOWithTimeout.java#L332-L368","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Treat InterruptedIOException as cancellation: abort the operation and release the channel/stream; do not blindly retry","Interrupt IO threads only as a last resort; prefer closing the channel, which unblocks the IO deterministically","If you catch it and swallow it, restore the flag with Thread.currentThread().interrupt() so upstream logic still sees the interrupt"],"exampleFix":"// before\nexecutor.shutdownNow(); // interrupts IO threads mid-read -> opaque failure\n\n// after\nexecutor.shutdown();\nif (!executor.awaitTermination(30, TimeUnit.SECONDS)) {\n  channel.close(); // unblocks IO deterministically\n  executor.shutdownNow();\n}","handlingStrategy":"try-catch","validationCode":"// no pre-check can prevent a concurrent interrupt; make cancellation cooperative\nif (Thread.currentThread().isInterrupted()) throw new InterruptedIOException();","typeGuard":null,"tryCatchPattern":"catch (InterruptedIOException e) {\n  Thread.currentThread().interrupt(); // preserve the interrupt status\n  abortTransferAndRelease();         // treat as cancellation, not a retryable error\n}","preventionTips":["Cancel IO by closing the channel; it unblocks reads deterministically","Never swallow InterruptedIOException without restoring the interrupt flag","Avoid shutdownNow() on pools that own in-flight socket IO"],"tags":["hadoop-common","network","interruption","concurrency","nio"],"backgroundTag":"interrupted-io","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}