{"record":{"id":"5631cc7f0c926cd3","repo":"dgraph-io/dgraph","slug":"task-does-not-exist-or-has-expired","errorCode":null,"errorMessage":"task does not exist or has expired","messagePattern":"task does not exist or has expired","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"worker/queue.go","lineNumber":206,"sourceCode":"\tdefault:\n\t\treturn 0, fmt.Errorf(\"too many pending tasks, please try again later\")\n\t}\n}\n\n// get retrieves metadata for a given task ID.\nfunc (t *tasks) get(id uint64) (TaskMeta, error) {\n\tif t == nil {\n\t\treturn 0, fmt.Errorf(\"task queue hasn't been initialized yet\")\n\t}\n\n\tif id == 0 || id == math.MaxUint64 {\n\t\treturn 0, fmt.Errorf(\"task ID is invalid: %d\", id)\n\t}\n\tt.logMu.Lock()\n\tdefer t.logMu.Unlock()\n\tmeta := TaskMeta(t.log.Get(id))\n\tif meta == 0 {\n\t\treturn 0, fmt.Errorf(\"task does not exist or has expired\")\n\t}\n\treturn meta, nil\n}\n\n// worker loops forever, running queued tasks one at a time. Any returned errors are logged.\nfunc (t *tasks) worker() {\n\tshouldCleanup := time.Tick(time.Hour)\n\n\tfor {\n\t\t// If the server is shutting down, return immediately. Else, fetch a task from the queue.\n\t\tvar task taskRequest\n\t\tselect {\n\t\tcase <-x.ServerCloser.HasBeenClosed():\n\t\t\tif err := t.log.Close(); err != nil {\n\t\t\t\tglog.Warningf(\"error closing log file: %v\", err)\n\t\t\t}\n\t\t\treturn\n\t\tcase <-shouldCleanup:","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/queue.go#L188-L224","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Route the query through TaskStatusOverNetwork so it reaches the Alpha whose Raft ID is encoded in the task ID","If the Alpha restarted, the log is gone — re-run the backup/export and use the new task ID","Check the Alpha's logs for the original task run to recover its outcome","Validate the task ID source; confirm it came from a successful Enqueue on this cluster"],"exampleFix":"// before\nmeta, err := tasks.get(id) // fails after restart / wrong alpha\n// after\nmeta, err := worker.TaskStatusOverNetwork(ctx, &pb.TaskStatusRequest{TaskId: id})\nif err != nil {\n    return fmt.Errorf(\"task %d not found locally; trying originating alpha: %w\", id, err)\n}","handlingStrategy":"fallback","validationCode":"// Ensure the ID encodes a raft ID that exists in the current cluster\nif id>>32 == 0 { return fmt.Errorf(\"task ID carries no raft origin\") }","typeGuard":"func taskMayExist(id uint64) bool { return id != 0 && id != math.MaxUint64 } // existence only provable by lookup","tryCatchPattern":"meta, err := tasks.Get(id)\nif err != nil && strings.Contains(err.Error(), \"does not exist or has expired\") {\n    // fallback: cross-alpha lookup, then treat as unknown\n    meta, err = worker.TaskStatusOverNetwork(ctx, &pb.TaskStatusRequest{TaskId: id})\n    if err != nil { meta = nil }\n}","preventionTips":["Persist task results durably if you need them to survive Alpha restarts","Always query via TaskStatusOverNetwork in multi-node clusters so the right Alpha answers","Treat task status as ephemeral — poll to completion before restarting the Alpha","Never assume an old task ID is still queryable after maintenance windows"],"tags":["task-queue","state","distributed-systems","dgraph"],"backgroundTag":"task-not-found","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}