{"record":{"id":"9a25a4f9cd24b1f6","repo":"hashicorp/nomad","slug":"failed-to-set-driver-state-v-9a25a4","errorCode":null,"errorMessage":"failed to set driver state: %v","messagePattern":"failed to set driver state: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/mock/driver.go","lineNumber":516,"sourceCode":"\t\tlogger:          d.logger.With(\"task_name\", cfg.Name),\n\t\twaitCh:          make(chan interface{}),\n\t\tkillCh:          killCtx.Done(),\n\t\tkill:            killCancel,\n\t\tstartedAt:       time.Now(),\n\t}\n\n\tdriverState := MockTaskState{\n\t\tStartedAt:       h.startedAt,\n\t\tCommand:         driverConfig.Command,\n\t\tExecCommand:     driverConfig.ExecCommand,\n\t\tPluginExitAfter: driverConfig.pluginExitAfterDuration,\n\t\tKillAfter:       driverConfig.killAfterDuration,\n\t}\n\thandle := drivers.NewTaskHandle(taskHandleVersion)\n\thandle.Config = cfg\n\tif err := handle.SetDriverState(&driverState); err != nil {\n\t\td.logger.Error(\"failed to start task, error setting driver state\", \"error\", err, \"task_name\", cfg.Name)\n\t\treturn nil, nil, fmt.Errorf(\"failed to set driver state: %v\", err)\n\t}\n\n\td.tasks.Set(cfg.ID, h)\n\n\td.logger.Debug(\"starting task\", \"task_name\", cfg.Name)\n\tgo h.run()\n\treturn handle, net, nil\n\n}\n\nfunc (d *Driver) WaitTask(ctx context.Context, taskID string) (<-chan *drivers.ExitResult, error) {\n\thandle, ok := d.tasks.Get(taskID)\n\tif !ok {\n\t\treturn nil, drivers.ErrTaskNotFound\n\t}\n\n\tch := make(chan *drivers.ExitResult)\n\tgo d.handleWait(ctx, handle, ch)","sourceCodeStart":498,"sourceCodeEnd":534,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/mock/driver.go#L498-L534","documentation":"After building the task handle, StartTask persists the mock driver's TaskState via handle.SetDriverState. If serialization/storage of the driver state fails, the task is not registered and this error wraps the underlying cause.","triggerScenarios":"handle.SetDriverState returning an error during StartTask — e.g. the TaskHandle's state store failing to encode or persist the driverState struct.","commonSituations":"Internal client state-store corruption; incompatible driver state schema after a Nomad client upgrade/restoring an old allocation directory; disk issues on the client.","solutions":["Inspect the logged 'error setting driver state' message for the root cause.","Retry StartTask; transient state-store failures typically resolve on re-attempt.","If it persists after an upgrade, clean the client's allocation/state data for the affected task."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"h, net, err := drv.StartTask(ctx, cfg)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to set driver state\") {\n        // inspect client logs for 'error setting driver state', then retry\n        h, net, err = drv.StartTask(ctx, cfg)\n    }\n    if err != nil {\n        return err\n    }\n}","preventionTips":["Keep Nomad client state directories healthy and on reliable storage.","Avoid mixing driver state files across Nomad version upgrades."],"tags":["nomad","mock-driver","state-persistence"],"backgroundTag":"driver-state-write-failed","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"}