{"record":{"id":"122e2fa46378cd5f","repo":"apache/beam","slug":"failed-to-create-subscription-to-topic-s-on-project-s-s","errorCode":null,"errorMessage":"Failed to create subscription to topic %s on project %s: %s","messagePattern":"Failed to create subscription to topic (.+?) on project (.+?): (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/PubsubUnboundedSource.java","lineNumber":1475,"sourceCode":"          topicPath);\n      projectPath = PubsubClient.projectPathFromId(projectId);\n    }\n\n    try {\n      try (PubsubClient pubsubClient =\n          pubsubFactory.newClient(\n              timestampAttribute, idAttribute, options.as(PubsubOptions.class))) {\n        SubscriptionPath subscriptionPath =\n            pubsubClient.createRandomSubscription(projectPath, topicPath, DEAULT_ACK_TIMEOUT_SEC);\n        LOG.warn(\n            \"Created subscription {} to topic {}.\"\n                + \" Note this subscription WILL NOT be deleted when the pipeline terminates\",\n            subscriptionPath,\n            topic);\n        return subscriptionPath;\n      }\n    } catch (Exception e) {\n      throw new RuntimeException(\n          String.format(\n              \"Failed to create subscription to topic %s on project %s: %s\",\n              topicPath, projectPath, e.getMessage()),\n          e);\n    }\n  }\n}\n","sourceCodeStart":1457,"sourceCodeEnd":1483,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/PubsubUnboundedSource.java#L1457-L1483","documentation":"PubsubUnboundedSource's subscription auto-creation path wraps any Exception during PubsubClient.createSubscription into RuntimeException(\"Failed to create subscription to topic %s on project %s: %s\", e). It is thrown when reading from a topic path requires Beam to create a scratch subscription and the Pubsub API call fails. The formatted message carries the topic path, project path, and underlying error message.","triggerScenarios":"Using PubsubIO.read().topic(topicPath) (no explicit subscription) where Beam must create a subscription, and creation fails: permission denied (needs pubsub.subscriptions.create on the project), invalid topic path, topic doesn't exist, or API/quota errors.","commonSituations":"Service account lacking Pubsub Editor/Subscriber+Editor roles; reading from a topic in another project without cross-project permissions; deleted topic still referenced; transient Pubsub API outage during pipeline startup.","solutions":["Pre-create the subscription and pass it via fromSubscription(...) instead of relying on auto-creation.","Grant the pipeline service account roles/pubsub.editor (or subscriptions.create + topic attach) on the target project.","Verify the topic exists and the topic path/project strings are correct.","Check the chained cause message for quota/API-specific errors and address those (quota increase, retry later)."],"exampleFix":"// before\nPubsubIO.readMessages().fromTopic(\"projects/myproj/topics/mytopic\") // auto-create may fail\n// after\n// gcloud pubsub subscriptions create mytopic-sub --topic=mytopic --topic-project=myproj\nPubsubIO.readMessages().fromSubscription(\"projects/myproj/subscriptions/mytopic-sub\");","handlingStrategy":"retry","validationCode":"gcloud pubsub topics describe <topicPath>\ngcloud projects get-iam-policy <project> --flatten=\"bindings[].members\" --filter=\"bindings.members:<svc-account>\"","typeGuard":"null","tryCatchPattern":"try { read.fromTopic(topic); } catch (RuntimeException e) { LOG.error(\"subscription creation failed: {}\", e.getCause()); /* fall back to pre-created subscription */ }","preventionTips":["Pre-create subscriptions in IaC (Terraform/gcloud) and reference them explicitly.","Grant the pipeline service account pubsub editor roles on the project.","Monitor Pubsub API quota and outages during deployment windows."],"tags":["java","pubsub","permissions","gcp"],"backgroundTag":"subscription-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}