apache/hadoop · error · NotFoundException

task not found with id {}

Error message

task not found with id {}

What it means

The task id string parsed into a valid TaskId, but job.getTask(taskID) returned null: the running ApplicationMaster does not know this task under that job. AMWebServices reports it as HTTP 404 with 'task not found with id <tid>'.

Source

Thrown at hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AMWebServices.java:186

    } catch (YarnRuntimeException e) {
      // TODO: after MAPREDUCE-2793 YarnRuntimeException is probably not expected here
      // anymore but keeping it for now just in case other stuff starts failing.
      // Also, the webservice should ideally return BadRequest (HTTP:400) when
      // the id is malformed instead of NotFound (HTTP:404). The webserver on
      // top of which AMWebServices is built seems to automatically do that for
      // unhandled exceptions
      throw new NotFoundException(e.getMessage());
    } catch (NumberFormatException ne) {
      throw new NotFoundException(ne.getMessage());
    } catch (IllegalArgumentException e) {
      throw new NotFoundException(e.getMessage());
    } 
    if (taskID == null) {
      throw new NotFoundException("taskid " + tid + " not found or invalid");
    }
    task = job.getTask(taskID);
    if (task == null) {
      throw new NotFoundException("task not found with id " + tid);
    }
    return task;
  }

  /**
   * convert a task attempt id string to an actual task attempt and handle all
   * the error checking.
   */
  public static TaskAttempt getTaskAttemptFromTaskAttemptString(String attId, Task task)
      throws NotFoundException {
    TaskAttemptId attemptId;
    TaskAttempt ta;
    try {
      attemptId = MRApps.toTaskAttemptID(attId);
    } catch (YarnRuntimeException e) {
      // TODO: after MAPREDUCE-2793 YarnRuntimeException is probably not expected here
      // anymore but keeping it for now just in case other stuff starts failing.
      // Also, the webservice should ideally return BadRequest (HTTP:400) when

View on GitHub (pinned to 2add963021)

Solutions

  1. List tasks with GET /ws/v1/mapreduce/jobs/{jobid}/tasks and use an id from that response
  2. Verify the job portion of the task id (task_<ts>_<seq>_...) equals the {jobid} in the URL
  3. If the job already finished, query the Job History Server REST API (/ws/v1/history) instead of the AM

Example fix

// before: task id from job 0001 sent to job 0002
GET /ws/v1/mapreduce/jobs/job_1401318629735_0002/tasks/task_1401318629735_0001_m_000003
// 404 { "task not found with id ..." }

// after: job part of the task id matches the URL
GET /ws/v1/mapreduce/jobs/job_1401318629735_0001/tasks/task_1401318629735_0001_m_000003
Defensive patterns

Strategy: validation

Validate before calling

// The task id embeds its job id: task_<ts>_<seq>_... must extend the URL's jid
String expectedPrefix = "task_" + jid.substring("job_".length());
if (!tid.startsWith(expectedPrefix)) {
  // task cannot belong to this job; skip the request or refresh the id
}

Type guard

static boolean taskBelongsToJob(String tid, String jid) {
  return tid != null && jid != null
      && tid.startsWith("task_" + jid.substring(4));
}

Try / catch

try {
  return getTask(jid, tid);
} catch (javax.ws.rs.NotFoundException e) {
  // id valid but unknown to this job: re-list tasks and retry once with a fresh id
  tasks = listTasks(jid);
}

Prevention

When it happens

Trigger: GET /ws/v1/mapreduce/jobs/{jobid}/tasks/{taskid} (and its /counters, /attempts sub-resources) where the task id belongs to a different job, has a wrong sequence number or task-type letter, or the task never existed in this job.

Common situations: Task id reused from a previous run of the job (the job part embedded in the task id differs from {jobid}); copy-paste between jobs; querying after the job restarted so ids shifted; scripted iteration over stale ids.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/9ce627cde35a2f54. Report an issue: GitHub.