{"record":{"id":"b1136c141fcc3c90","repo":"hashicorp/nomad","slug":"failed-to-receive-initial-message-v-b1136c","errorCode":null,"errorMessage":"failed to receive initial message: %v","messagePattern":"failed to receive initial message: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/drivers/server.go","lineNumber":319,"sourceCode":"\t}\n\n\tresult, err := b.impl.ExecTask(req.TaskId, req.Command, timeout)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tresp := &proto.ExecTaskResponse{\n\t\tStdout: result.Stdout,\n\t\tStderr: result.Stderr,\n\t\tResult: exitResultToProto(result.ExitResult),\n\t}\n\n\treturn resp, nil\n}\n\nfunc (b *driverPluginServer) ExecTaskStreaming(server proto.Driver_ExecTaskStreamingServer) error {\n\tmsg, err := server.Recv()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to receive initial message: %v\", err)\n\t}\n\n\tif msg.Setup == nil {\n\t\treturn fmt.Errorf(\"first message should always be setup\")\n\t}\n\n\tif impl, ok := b.impl.(ExecTaskStreamingRawDriver); ok {\n\t\treturn impl.ExecTaskStreamingRaw(server.Context(),\n\t\t\tmsg.Setup.TaskId, msg.Setup.Command, msg.Setup.Tty,\n\t\t\tserver)\n\t}\n\n\td, ok := b.impl.(ExecTaskStreamingDriver)\n\tif !ok {\n\t\treturn fmt.Errorf(\"driver does not support exec\")\n\t}\n\n\texecOpts, errCh := StreamToExecOptions(server.Context(),","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/plugins/drivers/server.go#L301-L337","documentation":"ExecTaskStreaming is the plugin-server side handler for the Driver_ExecTaskStreaming RPC. The first gRPC message from the client must be received to learn the task/exec setup; this error wraps any failure of that initial server.Recv() call (transport closed, stream canceled, decode failure).","triggerScenarios":"Calling driverPluginServer.ExecTaskStreaming when the client closes/cancels the stream before sending any message, the gRPC connection drops, or the initial ExecTaskStreamingRequest fails to deserialize.","commonSituations":"Client task/plugin crashes right after starting an exec stream; context cancellation or RPC deadline expiring before the first message; network interruption between Nomad client and driver plugin process; mismatched plugin protocol versions causing undecodable messages.","solutions":["Check the wrapped %v error: if it is context canceled/deadline exceeded, verify the caller's exec timeout and stream cancellation logic.","Ensure the client always sends the initial ExecTaskStreamingRequest with a Setup message immediately after opening the stream.","Verify the driver plugin binary is compatible with the Nomad client's plugin protocol version and is not crashing (check plugin stderr/logs).","Retry the exec request; transient gRPC disconnects between client and plugin are often temporary."],"exampleFix":"// before\nmsg, err := server.Recv()\nif err != nil {\n\treturn fmt.Errorf(\"failed to receive initial message: %v\", err)\n}\n// after\nmsg, err := server.Recv()\nif err != nil {\n\tif server.Context().Err() != nil {\n\t\treturn fmt.Errorf(\"exec stream canceled before initial message: %w\", err)\n\t}\n\treturn fmt.Errorf(\"failed to receive initial message: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// Before initiating exec, ensure the plugin client is healthy\nif err := clientPing(drvPlugin); err != nil {\n\treturn fmt.Errorf(\"driver plugin unreachable before exec: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"err := srv.ExecTaskStreaming(ctx)\nif err != nil && strings.Contains(err.Error(), \"failed to receive initial message\") {\n\t// inspect wrapped cause; if context.Canceled/DeadlineExceeded, retry with longer deadline\n}","preventionTips":["Always send the Setup frame immediately after opening the exec stream.","Keep RPC deadlines longer than the expected exec duration.","Monitor plugin process crashes and restarts.","Pin plugin binary versions to the host protocol version."],"tags":["grpc","streaming","exec","plugin"],"backgroundTag":"grpc-stream-receive-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"}