dgraph-io/dgraph · warning

task does not exist or has expired

Error message

task does not exist or has expired

What it means

get looks up the task's metadata in the in-memory/raff log; a zero value means no task with that ID has ever been recorded in this process's log. Tasks are transient, so IDs from a restarted Alpha or expired entries also return this error.

Source

Thrown at worker/queue.go:206

	default:
		return 0, fmt.Errorf("too many pending tasks, please try again later")
	}
}

// get retrieves metadata for a given task ID.
func (t *tasks) get(id uint64) (TaskMeta, error) {
	if t == nil {
		return 0, fmt.Errorf("task queue hasn't been initialized yet")
	}

	if id == 0 || id == math.MaxUint64 {
		return 0, fmt.Errorf("task ID is invalid: %d", id)
	}
	t.logMu.Lock()
	defer t.logMu.Unlock()
	meta := TaskMeta(t.log.Get(id))
	if meta == 0 {
		return 0, fmt.Errorf("task does not exist or has expired")
	}
	return meta, nil
}

// worker loops forever, running queued tasks one at a time. Any returned errors are logged.
func (t *tasks) worker() {
	shouldCleanup := time.Tick(time.Hour)

	for {
		// If the server is shutting down, return immediately. Else, fetch a task from the queue.
		var task taskRequest
		select {
		case <-x.ServerCloser.HasBeenClosed():
			if err := t.log.Close(); err != nil {
				glog.Warningf("error closing log file: %v", err)
			}
			return
		case <-shouldCleanup:

View on GitHub (pinned to 759e242be6)

Solutions

  1. Route the query through TaskStatusOverNetwork so it reaches the Alpha whose Raft ID is encoded in the task ID
  2. If the Alpha restarted, the log is gone — re-run the backup/export and use the new task ID
  3. Check the Alpha's logs for the original task run to recover its outcome
  4. Validate the task ID source; confirm it came from a successful Enqueue on this cluster

Example fix

// before
meta, err := tasks.get(id) // fails after restart / wrong alpha
// after
meta, err := worker.TaskStatusOverNetwork(ctx, &pb.TaskStatusRequest{TaskId: id})
if err != nil {
    return fmt.Errorf("task %d not found locally; trying originating alpha: %w", id, err)
}
Defensive patterns

Strategy: fallback

Validate before calling

// Ensure the ID encodes a raft ID that exists in the current cluster
if id>>32 == 0 { return fmt.Errorf("task ID carries no raft origin") }

Type guard

func taskMayExist(id uint64) bool { return id != 0 && id != math.MaxUint64 } // existence only provable by lookup

Try / catch

meta, err := tasks.Get(id)
if err != nil && strings.Contains(err.Error(), "does not exist or has expired") {
    // fallback: cross-alpha lookup, then treat as unknown
    meta, err = worker.TaskStatusOverNetwork(ctx, &pb.TaskStatusRequest{TaskId: id})
    if err != nil { meta = nil }
}

Prevention

When it happens

Trigger: Calling get/TaskStatus with an ID that was never enqueued on this Alpha, or whose log entry was lost due to a process restart, or which was created on a different Alpha.

Common situations: Polling a task ID after the Alpha restarted (in-memory log gone); sending the status query to the wrong Alpha in a multi-node cluster (use TaskStatusOverNetwork/resolveTask instead); polling long after the task completed and its entry aged out; typo'd or truncated task ID.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/5631cc7f0c926cd3. Report an issue: GitHub.