{"record":{"id":"8ced6d835bf187b0","repo":"apache/hadoop","slug":"task-set-failed-with-an-uncaught-throwable","errorCode":null,"errorMessage":"Task set failed with an uncaught throwable","messagePattern":"Task set failed with an uncaught throwable","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"hadoop-cloud-storage-project/hadoop-tos/src/main/java/org/apache/hadoop/fs/tosfs/common/Tasks.java","lineNumber":272,"sourceCode":"              try {\n                abortTask.run(iterator.next());\n              } catch (Exception e) {\n                failed = true;\n                LOG.error(\"Failed to abort task\", e);\n                // keep going\n              }\n              if (stopAbortsOnFailure && failed) {\n                break;\n              }\n            }\n          }\n        }\n      }\n\n      if (throwFailureWhenFinished && !exceptions.isEmpty()) {\n        Tasks.throwOne(exceptions, exceptionClass);\n      } else if (throwFailureWhenFinished && threw) {\n        throw new RuntimeException(\"Task set failed with an uncaught throwable\");\n      }\n\n      return !threw;\n    }\n\n    private void tryRunOnFailure(I item, Exception failure) {\n      try {\n        onFailure.run(item, failure);\n      } catch (Exception failException) {\n        failure.addSuppressed(failException);\n        LOG.error(\"Failed to clean up on failure\", failException);\n        // keep going\n      }\n    }\n\n    private <E extends Exception> boolean runParallel(\n        final Task<I, E> task, Class<E> exceptionClass) throws E {\n      final Queue<I> succeeded = new ConcurrentLinkedQueue<>();","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-tos/src/main/java/org/apache/hadoop/fs/tosfs/common/Tasks.java#L254-L290","documentation":"Tasks (a retry/parallel helper copied from Apache Iceberg and used by the TOS committer for commit/cleanup) throws this generic RuntimeException from its single-threaded run path when the failure flag indicates a throwable escaped, but no Exception was captured to rethrow. Per the code comment, `threw` stays true only for throwables NOT caught by the per-item catch block, i.e. an Error (OOM, linkage errors) or a failure of the items iterable itself. The real cause is only visible in surrounding logs.","triggerScenarios":"new Tasks.Builder(items)...run(task) without an executor, where a task body throws an Error/Throwable instead of an Exception (Out OfMemoryError, NoSuchMethodError, StackOverflowError), or items.iterator() throws while iterating; throwFailureWhenFinished is enabled (default true) so the failure is surfaced at the end.","commonSituations":"Abort/cleanup phases of the TOS committer running with an undersized task heap (OOM inside an abort-upload task); classpath conflicts between the TOS SDK and Hadoop producing NoSuchMethodError/NoClassDefFoundError inside a task lambda; lazily-built item collections that throw during iteration.","solutions":["Search the task and worker logs around this exception for the true cause: OOM messages, 'Failed to clean up on failure', 'Failed to revert task', or linkage-error stack traces — the RuntimeException itself carries no cause","If the underlying throwable is OutOfMemoryError, raise the task/container heap (mapreduce.map/reduce.memory.mb and java.opts) so it never occurs","For NoSuchMethodError/NoClassDefFoundError, align jar versions: put a single matching version of the TOS SDK and hadoop-tos on the classpath and remove duplicates","Configure real retries on the builder (.retry(n).exponentialBackoff(...)) so transient failures flow through the typed-exception path and are rethrown with their actual cause"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  new Tasks.Builder<>(items)\n      .retry(3).exponentialBackoff(1000, 600000, 2.0)\n      .run(task);\n} catch (RuntimeException e) {\n  if (\"Task set failed with an uncaught throwable\".equals(e.getMessage())) {\n    // the original Error was never captured: go find it in the worker logs (OOM, linkage errors)\n    LOG.error(\"Uncaught Error inside task set; check heap/classpath. Items: {}\", items, e);\n  }\n  throw e;\n}","preventionTips":["Wrap task bodies so Throwables are captured as Exceptions: try { ... } catch (Throwable t) { throw new RuntimeException(t); }","Size task/mapreduce heap generously when tasks buffer data — OOM is the most common uncaught Error here","Pin exact versions of the TOS SDK and hadoop-tos jars to avoid NoSuchMethodError inside tasks","Make the items iterable cheap and safe: build the list before entering the builder so iterator failures cannot occur"],"tags":["hadoop","tos","concurrency","error-handling","iceberg-tasks"],"backgroundTag":"uncaught-throwable-in-task","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}