{"record":{"id":"36d76e5477ee372e","repo":"hashicorp/nomad","slug":"task-with-id-q-already-started-36d76e","errorCode":null,"errorMessage":"task with ID %q already started","messagePattern":"task with ID %q already started","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/java/driver.go","lineNumber":434,"sourceCode":"\t\texec:         execImpl,\n\t\tpid:          taskState.Pid,\n\t\tpluginClient: pluginClient,\n\t\ttaskConfig:   taskState.TaskConfig,\n\t\tprocState:    drivers.TaskStateRunning,\n\t\tstartedAt:    taskState.StartedAt,\n\t\texitResult:   &drivers.ExitResult{},\n\t\tlogger:       d.logger,\n\t}\n\n\td.tasks.Set(taskState.TaskConfig.ID, h)\n\n\tgo h.run()\n\treturn nil\n}\n\nfunc (d *Driver) StartTask(cfg *drivers.TaskConfig) (handle *drivers.TaskHandle, network *drivers.DriverNetwork, err error) {\n\tif _, ok := d.tasks.Get(cfg.ID); ok {\n\t\treturn nil, nil, fmt.Errorf(\"task with ID %q already started\", cfg.ID)\n\t}\n\n\tvar driverConfig TaskConfig\n\tif err := cfg.DecodeDriverConfig(&driverConfig); err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"failed to decode driver config: %v\", err)\n\t}\n\n\tif err := driverConfig.validate(); err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"failed driver config validation: %v\", err)\n\t}\n\n\tif driverConfig.Class == \"\" && driverConfig.JarPath == \"\" {\n\t\treturn nil, nil, fmt.Errorf(\"jar_path or class must be specified\")\n\t}\n\n\tabsPath, err := GetAbsolutePath(\"java\")\n\tif err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"failed to find java binary: %s\", err)","sourceCodeStart":416,"sourceCodeEnd":452,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/java/driver.go#L416-L452","documentation":"This error is returned by StartTask when a task with the same ID is already tracked by the driver in its in-memory tasks map. Nomad task IDs are unique per allocation, so this indicates duplicate startup for the same task, most often a race or a client bug that calls StartTask twice. It prevents double-running the same task within the driver.","triggerScenarios":"Calling StartTask twice with a *drivers.TaskConfig whose ID is already present in d.tasks; concurrent starts racing past the Get check; client state restore followed by an explicit start.","commonSituations":"Driver plugin bugs or custom automation invoking the driver directly; recovery logic replaying starts; test harnesses reusing task IDs without cleanup.","solutions":["Verify the task ID is unique per allocation and not reused","Check whether the task is already running (d.tasks / nomad alloc status) before starting","Stop the existing task/allocation before starting a new one with the same ID","If caused by a race or recovery bug, restart the Nomad client and report the issue"],"exampleFix":"// before\nhandle, _, _ := driver.StartTask(cfg) // called twice for same cfg.ID\n// after\nif _, ok := driver.(*javaDriver).tasks.Get(cfg.ID); !ok {\n    handle, _, _ = driver.StartTask(cfg)\n}","handlingStrategy":"validation","validationCode":"// ensure unique task IDs before starting\nids := map[string]bool{}\nfor _, t := range group.Tasks {\n    if ids[t.Name] { return errors.New(\"duplicate task id\") }\n    ids[t.Name] = true\n}","typeGuard":null,"tryCatchPattern":"if _, _, err := driver.StartTask(cfg); err != nil {\n    if strings.Contains(err.Error(), \"already started\") {\n        // treat as success or stop the existing task first\n    }\n}","preventionTips":["Never reuse task IDs across starts; derive them from unique alloc IDs","Serialize StartTask calls per task to avoid races","Clean up d.tasks entries when tasks are destroyed","Let Nomad's driver manager drive starts instead of custom automation"],"tags":["nomad","java-driver","start-task","duplicate-task"],"backgroundTag":"task-already-started","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"}