{"record":{"id":"411b9bae02708447","repo":"dgraph-io/dgraph","slug":"task-failed","errorCode":null,"errorMessage":"task failed","messagePattern":"task failed","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"worker/queue.go","lineNumber":152,"sourceCode":"\t}\n\n\tid, err := t.enqueue(req)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\n\t// Wait for upto 3 seconds to check for errors.\n\tfor range 3 {\n\t\ttime.Sleep(time.Second)\n\n\t\tt.logMu.Lock()\n\t\tmeta := TaskMeta(t.log.Get(id))\n\t\tt.logMu.Unlock()\n\n\t\t// Early return\n\t\tswitch meta.Status() {\n\t\tcase TaskStatusFailed:\n\t\t\treturn 0, fmt.Errorf(\"task failed\")\n\t\tcase TaskStatusSuccess:\n\t\t\treturn id, nil\n\t\t}\n\t}\n\n\treturn id, nil\n}\n\n// enqueue adds a new task to the queue. This must be of type:\n// - *pb.BackupRequest\n// - *pb.ExportRequest\nfunc (t *tasks) enqueue(req interface{}) (uint64, error) {\n\tvar kind TaskKind\n\tswitch req.(type) {\n\tcase *pb.BackupRequest:\n\t\tkind = TaskKindBackup\n\tcase *pb.ExportRequest:\n\t\tkind = TaskKindExport","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/queue.go#L134-L170","documentation":"After enqueuing, Enqueue polls the task log for up to ~3 seconds and returns immediately with 'task failed' if the task's metadata transitions to TaskStatusFailed. This is the early-failure signal from the task worker — the task started and failed quickly (within the 3s window).","triggerScenarios":"Enqueue a backup or export request whose execution fails almost immediately (e.g. handler returns an error right away) so the polling loop observes TaskStatusFailed and returns fmt.Errorf(\"task failed\").","commonSituations":"Backups failing instantly due to bad S3/destination credentials; export failing on an invalid or inaccessible target path; permission errors on the storage backend; malformed request parameters rejected by the task handler at start.","solutions":["Read the Alpha logs around the task ID for the underlying task error (this error itself carries no detail)","Fix the task destination/permissions (e.g. S3 credentials, bucket, path) and re-enqueue","Validate the request (BackupRequest/ExportRequest fields, target format) before enqueueing","Instead of relying on Enqueue's 3s window, poll TaskStatus with the returned task ID for the authoritative status"],"exampleFix":"// before\nid, err := tasks.Enqueue(req)\nif err != nil { return err } // \"task failed\" with no detail\n// after\nid, err := tasks.Enqueue(req)\nif err != nil {\n    return fmt.Errorf(\"task %d failed, see alpha logs for cause: %w\", id, err)\n}\n// then poll task status for detailed progress\nmeta, err := tasks.Get(id)","handlingStrategy":"try-catch","validationCode":"// Validate the destination before enqueueing\nclassic := func() error {\n    if bucket == \"\" || accessKey == \"\" { return fmt.Errorf(\"incomplete backup destination\") }\n    return nil\n}()","typeGuard":null,"tryCatchPattern":"id, err := tasks.Enqueue(req)\nif err != nil && strings.Contains(err.Error(), \"task failed\") {\n    // fetch real cause from alpha logs / task status\n    meta, _ := tasks.Get(id)\n    return fmt.Errorf(\"task %d failed: status=%v\", id, meta.Status())\n}","preventionTips":["Pre-validate backup/export destinations (credentials, paths, permissions)","Do not rely on Enqueue's 3s early-return for final status; poll TaskStatus","Grep Alpha logs by task ID for the underlying failure","Test backup configuration with a dry run before scheduling it"],"tags":["task-queue","async","backup-export","dgraph"],"backgroundTag":"task-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}