apache/hadoop · error · NotFoundException

taskid {} not found or invalid

Error message

taskid {} not found or invalid

What it means

Thrown by the MapReduce ApplicationMaster REST API (AMWebServices, usually http://<am-host>:8099/ws/v1/mapreduce). The {taskid} path parameter was converted with MRApps.toTaskID(), which returned null (null/empty input or a string that is not a task id) instead of throwing. JAX-RS NotFoundException maps this to HTTP 404 even though a malformed id is semantically a 400; the in-code comment at AMWebServices.java:171-173 admits this.

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:182

    TaskId taskID;
    Task task;
    try {
      taskID = MRApps.toTaskID(tid);
    } 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);

View on GitHub (pinned to 2add963021)

Solutions

  1. Use the exact task id returned by GET /ws/v1/mapreduce/jobs/{jobid}/tasks instead of building one by hand
  2. Check the format: task_<jobTimestamp>_<jobSeq>_[m|r]_<taskSeq>, e.g. task_1401318629735_0001_m_000003
  3. Trim and URL-encode/decode the parameter before sending
  4. If you must distinguish 'malformed' from 'missing', validate the format client-side: the API returns 404 for both

Example fix

// before
GET /ws/v1/mapreduce/jobs/job_1401318629735_0001/tasks/0001_m_000003
// 404 { "taskid 0001_m_000003 not found or invalid" }

// after
GET /ws/v1/mapreduce/jobs/job_1401318629735_0001/tasks/task_1401318629735_0001_m_000003
Defensive patterns

Strategy: validation

Validate before calling

private static final Pattern TASK_ID_RE =
    Pattern.compile("^task_\\d+_\\d+_[mr]_\\d+$");

if (tid == null || !TASK_ID_RE.matcher(tid).matches()) {
  throw new IllegalArgumentException("bad task id: " + tid); // do not call the AM
}

Type guard

static boolean isWellFormedTaskId(String tid) {
  return tid != null && tid.startsWith("task_")
      && tid.split("_").length == 5;
}

Try / catch

try {
  TaskInfo t = client.target(amBase).path("jobs/{jid}/tasks/{tid}")
      .resolveTemplates(Map.of("jid", jid, "tid", tid))
      .request(MediaType.APPLICATION_JSON).get(TaskInfo.class);
} catch (javax.ws.rs.NotFoundException nfe) {
  // 404 covers both malformed and unknown ids here; treat as 'no such task'
}

Prevention

When it happens

Trigger: Calling endpoints that embed a task id - GET /ws/v1/mapreduce/jobs/{jobid}/tasks/{taskid}, /tasks/{taskid}/counters, /tasks/{taskid}/attempts/... , PUT /tasks/{taskid}/attempts/{attemptid}/state - with a taskid that is empty, lacks the 'task_' prefix (for example '0001_m_000003' or an attempt_... id), or cannot be parsed into a TaskId.

Common situations: Client code builds the id by string concatenation and drops the prefix; an attempt id is sent where a task id is expected; ids copy-pasted from history-server or log URLs with different formatting; untrimmed whitespace or bad URL encoding.

Related errors


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