{"record":{"id":"efbc5ece0a8c7213","repo":"googleapis/mcp-toolbox","slug":"failed-to-create-dataproc-session-template-client","errorCode":null,"errorMessage":"failed to create dataproc session template client: %w","messagePattern":"failed to create dataproc session template client: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/serverlessspark/serverlessspark.go","lineNumber":80,"sourceCode":"\nfunc (r Config) SourceConfigType() string {\n\treturn SourceType\n}\n\nfunc (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {\n\tua, err := util.UserAgentFromContext(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error in User Agent retrieval: %s\", err)\n\t}\n\tendpoint := fmt.Sprintf(\"%s-dataproc.googleapis.com:443\", r.Location)\n\tbatchClient, err := dataproc.NewBatchControllerClient(ctx, option.WithEndpoint(endpoint), option.WithUserAgent(ua))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create dataproc batch client: %w\", err)\n\t}\n\tsessionTemplateClient, err := dataproc.NewSessionTemplateControllerClient(ctx, option.WithEndpoint(endpoint), option.WithUserAgent(ua))\n\tif err != nil {\n\t\tbatchClient.Close()\n\t\treturn nil, fmt.Errorf(\"failed to create dataproc session template client: %w\", err)\n\t}\n\topsClient, err := longrunning.NewOperationsClient(ctx, option.WithEndpoint(endpoint), option.WithUserAgent(ua))\n\tif err != nil {\n\t\tbatchClient.Close()\n\t\tsessionTemplateClient.Close()\n\t\treturn nil, fmt.Errorf(\"failed to create longrunning client: %w\", err)\n\t}\n\tsessionClient, err := dataproc.NewSessionControllerClient(ctx, option.WithEndpoint(endpoint), option.WithUserAgent(ua))\n\tif err != nil {\n\t\tbatchClient.Close()\n\t\tsessionTemplateClient.Close()\n\t\topsClient.Close()\n\t\treturn nil, fmt.Errorf(\"failed to create dataproc session client: %w\", err)\n\t}\n\n\ts := &Source{\n\t\tConfig:                r,\n\t\tBatchClient:           batchClient,","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/serverlessspark/serverlessspark.go#L62-L98","documentation":"Initialize creates a SessionTemplateControllerClient after the batch client succeeds. If this second client cannot be constructed (credentials, endpoint, or network issues), the already-created batchClient is closed and the error is wrapped with this message. The wrapped cause from Google's client library identifies the specific problem.","triggerScenarios":"dataproc.NewSessionTemplateControllerClient(ctx, option.WithEndpoint(...), option.WithUserAgent(ua)) returns an error while NewBatchControllerClient previously succeeded — e.g. transient credential/API failure, endpoint resolution issue, or partially enabled APIs.","commonSituations":"Same credential/endpoint issues as the batch client but surfacing only here due to transient token fetch failure; region string valid for batch but session template API restricted by org policy; VPC Service Controls blocking the session template endpoint; intermittent network failures during multi-client setup.","solutions":["Retry Initialize — transient credential/token fetch failures often resolve; check wrapped cause for details.","Apply the same ADC/endpoint/API-enablement checks as the batch client: `gcloud services enable dataproc.googleapis.com`.","Check VPC Service Controls / org policies that may allow batch but block session template API calls to `<region>-dataproc.googleapis.com`.","Verify network stability and proxy settings to googleapis.com:443.","Confirm the service account has dataproc permissions covering session templates (roles/dataproc.editor)."],"exampleFix":"// before — org policy blocks the API, retry with valid egress\n// after — allow egress to <region>-dataproc.googleapis.com:443 and enable API\ngcloud services enable dataproc.googleapis.com --project my-project\nexport GOOGLE_APPLICATION_CREDENTIALS=/path/to/sa-key.json","handlingStrategy":"retry","validationCode":"// Same pre-flight as the batch client, plus org-policy awareness\n// Ensure both Dataproc surfaces are allowed before init:\ngcloud services list --enabled --project my-project | grep dataproc.googleapis.com\n# If behind VPC Service Controls, confirm the session template API is in the allowed list","typeGuard":null,"tryCatchPattern":"src, err := cfg.Initialize(ctx, tracer)\nif err != nil && strings.Contains(err.Error(), \"session template client\") {\n    // transient failures are common mid multi-client setup — retry once\n    time.Sleep(2 * time.Second)\n    src, err = cfg.Initialize(ctx, tracer)\n}\nif err != nil { return err }","preventionTips":["Confirm VPC Service Controls / org policies permit both batch and session template APIs in the region.","Check the wrapped cause: UNAVAILABLE/transient → retry; PERMISSION_DENIED → fix IAM; NOT_FOUND/endpoint → fix location.","Keep credentials and network stable across the whole multi-client initialization sequence.","Grant the identity roles/dataproc.editor so session template operations are permitted."],"tags":["serverless-spark","dataproc","gcp","client","authentication"],"backgroundTag":"missing-gcp-credentials","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}