{"record":{"id":"4b6fc2cf7c0921a7","repo":"apache/hadoop","slug":"interrupted-while-waiting-for-reading-task","errorCode":null,"errorMessage":"Interrupted while waiting for reading task","messagePattern":"Interrupted while waiting for reading task","errorType":"exception","errorClass":"InterruptedIOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java","lineNumber":1363,"sourceCode":"        futures.add(firstRequest);\n        Future<ByteBuffer> future = null;\n        try {\n          future = hedgedService.poll(\n              conf.getHedgedReadThresholdMillis(), TimeUnit.MILLISECONDS);\n          if (future != null) {\n            ByteBuffer result = future.get();\n            result.flip();\n            buf.put(result);\n            return;\n          }\n          DFSClient.LOG.debug(\"Waited {}ms to read from {}; spawning hedged \"\n              + \"read\", conf.getHedgedReadThresholdMillis(), chosenNode.info);\n          dfsClient.getHedgedReadMetrics().incHedgedReadOps();\n          // continue; no need to refresh block locations\n        } catch (ExecutionException e) {\n          futures.remove(future);\n        } catch (InterruptedException e) {\n          throw new InterruptedIOException(\n              \"Interrupted while waiting for reading task\");\n        }\n        // Ignore this node on next go around.\n        // If poll timeout and the request still ongoing, don't consider it\n        // again. If read data failed, don't consider it either.\n        ignored.add(chosenNode.info);\n      } else {\n        // We are starting up a 'hedged' read. We have a read already\n        // ongoing. Call getBestNodeDNAddrPair instead of chooseDataNode.\n        // If no nodes to do hedged reads against, pass.\n        boolean refetch = false;\n        try {\n          chosenNode = chooseDataNode(block, ignored, false);\n          if (chosenNode != null) {\n            // Latest block, if refreshed internally\n            block = chosenNode.block;\n            bb = ByteBuffer.allocate(len);\n            Callable<ByteBuffer> getFromDataNodeCallable =","sourceCodeStart":1345,"sourceCodeEnd":1381,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSInputStream.java#L1345-L1381","documentation":"Hedged-read path: while polling the first read future (dfs.client.hedged.read.threshold.millis elapsed, second read spawned), an InterruptedException from future.get() is converted to InterruptedIOException, aborting the hedged read loop. Pure thread-cancellation semantics; the data and cluster state are not implicated.","triggerScenarios":"Thread interrupt while hedged reads are enabled (dfs.client.hedged.read.threadpool.size > 0) and the reader waits on a CompletableFuture result.","commonSituations":"Task/job cancellation landing while hedged reads are in flight on slow clusters; shutdownNow() on reader thread pools.","solutions":["Propagate as cancellation; do not retry in the interrupted thread","Cancel readers by closing the stream instead of interrupting threads","Only enable hedged reads on pools you never interrupt mid-read"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"static boolean isCancelled(IOException e) {\n  return e instanceof InterruptedIOException;\n}","tryCatchPattern":"try {\n  n = in.read(buf);\n} catch (InterruptedIOException e) {\n  // cancelled while hedged reads were in flight: unwind cleanly\n  throw new java.util.concurrent.CancellationException(\"hedged read interrupted\", e);\n}","preventionTips":["Do not interrupt threads performing hedged reads; cancel via stream close","Scope hedged-read thread pools (dfs.client.hedged.read.threadpool.size) to non-interrupted executors"],"tags":["hdfs","interrupt","hedged-read","concurrency"],"backgroundTag":"thread-interrupted","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}