{"record":{"id":"c7e9961c864ce2f4","repo":"apache/hadoop","slug":"duration-of-a-task-shouldn-t-be-less-or-equal-to-0","errorCode":null,"errorMessage":"Duration of a task shouldn't be less or equal to 0!","messagePattern":"Duration of a task shouldn't be less or equal to 0!","errorType":"exception","errorClass":"YarnException","httpStatus":null,"severity":"error","filePath":"hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/TaskContainerDefinition.java","lineNumber":241,"sourceCode":"      taskContainerDef.allocationId = this.allocationId;\n      taskContainerDef.executionType = this.executionType;\n      taskContainerDef.hostname = this.hostname;\n      return taskContainerDef;\n    }\n\n    private long validateAndGetDuration(Builder builder) throws YarnException {\n      long duration = 0;\n\n      if (builder.duration != -1) {\n        duration = builder.duration;\n      } else if (builder.durationLegacy != -1) {\n        duration = builder.durationLegacy;\n      } else if (builder.taskStart != -1 && builder.taskFinish != -1) {\n        duration = builder.taskFinish - builder.taskStart;\n      }\n\n      if (duration <= 0) {\n        throw new YarnException(\"Duration of a task shouldn't be less or equal\"\n            + \" to 0!\");\n      }\n      return duration;\n    }\n  }\n}\n","sourceCodeStart":223,"sourceCodeEnd":248,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/TaskContainerDefinition.java#L223-L248","documentation":"Thrown by the Hadoop Scheduler Load Simulator (SLS) when TaskContainerDefinition.Builder.build() calls validateAndGetDuration(). The duration is resolved from builder.duration ('duration' in the task JSON), then builder.durationLegacy ('duration.ms'), then taskFinish - taskStart; if none is set (all default to -1, leaving duration == 0) or the resolved value is <= 0, a YarnException is thrown because SLS cannot schedule a container with zero or negative runtime.","triggerScenarios":"Building a TaskContainerDefinition (SLSRunner/SyntheticApplication parsing an sls input JSON, or rumen-trace conversion) where a task entry: omits 'duration', 'duration.ms', and both start/finish timestamps; sets duration to 0 or a negative number; or has taskFinish <= taskStart (reversed or equal timestamps).","commonSituations":"Hand-edited SLS JSON workload files with a typo'd key (e.g. 'duration_ms' instead of 'duration.ms'), traces exported with missing/zero timestamps, reusing old sample files whose tasks only carry start times, or copying durations in seconds where milliseconds were expected and rounding to 0.","solutions":["Add an explicit positive \"duration\" (milliseconds) to every task object in the SLS input JSON","Alternatively supply \"duration.ms\", or both start and finish timestamps with finish strictly greater than start","Validate the workload file before running SLS: for each task assert that a positive duration can be derived from duration/duration.ms/(finish-start)","If converting rumen traces, filter out or repair tasks whose finish time is not after start time"],"exampleFix":"// before (sls-input.json task)\n{\"type\" : \"map\", \"priority\" : 1, \"duration_ms\" : 100}\n// after\n{\"type\" : \"map\", \"priority\" : 1, \"duration\" : 100}","handlingStrategy":"validation","validationCode":"// before running SLS, verify every task yields a positive duration\nObjectMapper mapper = new ObjectMapper();\nJsonNode root = mapper.readTree(new File(\"sls-input.json\"));\nfor (JsonNode job : root.get(\"am\")) { /* am-level check as needed */ }\nfor (JsonNode task : root.get(\"jobs\")) {\n  long d = task.path(\"duration\").asLong(-1);\n  if (d == -1) d = task.path(\"duration.ms\").asLong(-1);\n  if (d == -1 && task.has(\"start\") && task.has(\"finish\")) d = task.get(\"finish\").asLong() - task.get(\"start\").asLong();\n  if (d <= 0) throw new IllegalArgumentException(\"Task with non-positive duration: \" + task);\n}","typeGuard":null,"tryCatchPattern":"catch (YarnException e) when building TaskContainerDefinition; report the offending task entry and stop the simulation run instead of letting it abort mid-load.","preventionTips":["Add duration to every task object when authoring SLS JSON; treat it as a required field","Keep a lint script (jq or the Java check above) in CI for workload files","When generating workloads from rumen traces, filter tasks whose finish <= start"],"tags":["hadoop-sls","yarn","workload-simulation","input-validation","configuration"],"backgroundTag":"config-validation-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}