{"record":{"id":"49ebbb3d76ae81a4","repo":"hashicorp/nomad","slug":"errtasknotfound","errorCode":"ErrTaskNotFound","errorMessage":"task not found for given id","messagePattern":"task not found for given id","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"info","filePath":"plugins/drivers/errors.go","lineNumber":8,"sourceCode":"// Copyright IBM Corp. 2015, 2026\n// SPDX-License-Identifier: MPL-2.0\n\npackage drivers\n\nimport \"errors\"\n\nvar ErrTaskNotFound = errors.New(\"task not found for given id\")\n\nvar ErrChannelClosed = errors.New(\"channel closed\")\n\nvar DriverRequiresRootMessage = \"Driver must run as root\"\n\nvar NoCgroupMountMessage = \"Failed to discover cgroup mount point\"\n\nvar CgroupMountEmpty = \"Cgroup mount point unavailable\"\n","sourceCodeStart":1,"sourceCodeEnd":17,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/plugins/drivers/errors.go#L1-L17","documentation":"drivers.ErrTaskNotFound (plugins/drivers/errors.go:8) is the sentinel error returned by driver handles when the task no longer exists inside the driver plugin (e.g. the task already exited or the plugin was restarted). In Nomad's task runner (client/allocrunner/taskrunner/task_runner.go:1109,1134) it is treated as success: a missing task during restore or Kill means there is nothing left to stop.","triggerScenarios":"Calling handle.Kill() or restore/recover logic for a task whose process the driver no longer tracks — the task already terminated, the exec plugin lost its task table, or the driver plugin process was restarted and lost state.","commonSituations":"Node crash/restart recovery where Nomad tries to restore running tasks but drivers have no record; killing a task that exited concurrently; docker/exec driver cleanup racing with the kill path.","solutions":["Nothing to fix in most cases — treat ErrTaskNotFound as task-already-stopped (Nomad does: returns nil)","If seen unexpectedly, check driver health and task state (nomad alloc status) to confirm the task truly exited","If restores persistently miss tasks, restart the client or driver plugin so state resyncs, and check driver logs for task table loss"],"exampleFix":"// before\nif err := handle.Kill(); err != nil {\n    return err\n}\n// after\nif err := handle.Kill(); err != nil {\n    if errors.Is(err, drivers.ErrTaskNotFound) {\n        return nil // task already gone\n    }\n    return err\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func isTaskNotFound(err error) bool { return errors.Is(err, drivers.ErrTaskNotFound) }","tryCatchPattern":"if err := handle.Kill(); err != nil {\n    if errors.Is(err, drivers.ErrTaskNotFound) {\n        return nil // already stopped\n    }\n    return fmt.Errorf(\"kill failed: %w\", err)\n}","preventionTips":["Always compare with errors.Is against the sentinel, never string matching","Treat ErrTaskNotFound as success in kill/restore paths","Watch for repeated occurrences as a sign of driver state loss"],"tags":["driver","task-lifecycle","sentinel-error"],"backgroundTag":"task-not-found","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}