{"record":{"id":"aadc96a93d7fd4eb","repo":"apache/hadoop","slug":"mroutput-mrerrthread-failed-aadc96","errorCode":null,"errorMessage":"MROutput/MRErrThread failed:","messagePattern":"MROutput/MRErrThread failed:","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-tools/hadoop-streaming/src/main/java/org/apache/hadoop/streaming/PipeReducer.java","lineNumber":97,"sourceCode":"    this.numOfReduceOutputKeyFields = job_.getInt(\"stream.num.reduce.output.key.fields\", 1);\n  }\n\n  public void reduce(Object key, Iterator values, OutputCollector output,\n                     Reporter reporter) throws IOException {\n\n    // init\n    if (doPipe_ && outThread_ == null) {\n      startOutputThreads(output, reporter);\n    }\n    try {\n      while (values.hasNext()) {\n        Writable val = (Writable) values.next();\n        numRecRead_++;\n        maybeLogRecord();\n        if (doPipe_) {\n          if (outerrThreadsThrowable != null) {\n            mapRedFinished();\n            throw new IOException(\"MROutput/MRErrThread failed:\",\n                outerrThreadsThrowable);\n          }\n          inWriter_.writeKey(key);\n          inWriter_.writeValue(val);\n        } else {\n          // \"identity reduce\"\n          output.collect(key, val);\n        }\n      }\n      if(doPipe_ && skipping) {\n        //flush the streams on every record input if running in skip mode\n        //so that we don't buffer other records surrounding a bad record. \n        clientOut_.flush();\n      }\n    } catch (IOException io) {\n      // a common reason to get here is failure of the subprocess.\n      // Document that fact, if possible.\n      String extraInfo = \"\";","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-tools/hadoop-streaming/src/main/java/org/apache/hadoop/streaming/PipeReducer.java#L79-L115","documentation":"Reducer-side twin of the mapper check: inside the reduce loop over values, PipeReducer.reduce() sees outerrThreadsThrowable set (the output or stderr reader thread for the piped reducer died) and throws IOException('MROutput/MRErrThread failed:', outerrThreadsThrowable) after calling mapRedFinished(). The cause chain holds the thread's original exception.","triggerScenarios":"With -reducer as an external tool, the thread reading reducer stdout or stderr fails mid-reduce — output that violates the expected format, pipe breakage when the reducer tool exits early, or custom stream.reduce.output.reader.class parse errors — and the next iteration of the value loop aborts.","commonSituations":"Reducer scripts emitting headers/debug lines to stdout, key-field count misconfiguration (stream.num.reduce.output.key.fields), reducers crashing partway through a value stream, or aggregator scripts buffering incorrectly and dying; wrapped cause in logs identifies which thread and why.","solutions":["Inspect the wrapped cause in the task log (MROutputThread/MRErrThread stack trace just before this IOException)","Conform reducer stdout to key\\tvalue lines; move logs/warnings to stderr","Match stream.num.reduce.output.key.fields and any custom reader class to what the tool actually prints","Test the reducer tool locally: cat input | reducer.sh and verify clean output and exit 0"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// preflight for the reducer tool: local pipeline smoke test\n// sh -c 'cat sample-group.txt | ./my_reducer.sh' must print clean key\\tvalue lines and exit 0","typeGuard":null,"tryCatchPattern":"catch IOException from reduce(); inspect the cause chain for the failed reader thread's exception and fix the output-format or tool-crash root cause; retrying the task without changes will fail identically.","preventionTips":["Keep reducer stdout strictly key\\tvalue; no headers or progress messages","Align stream.num.reduce.output.key.fields and custom reader classes with actual output","Handle partial input and empty groups gracefully in reducer scripts","Correlate with the subprocess exit-code error: thread failures often follow a tool crash"],"tags":["hadoop-streaming","output-parsing","threads","mapreduce","reducer"],"backgroundTag":"worker-thread-failure","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}