Title: Pubsub: Unbounded retry forced when publishing with message ordering enabled · Issue #1702 · googleapis/java-pubsub · GitHub
Open Graph Title: Pubsub: Unbounded retry forced when publishing with message ordering enabled · Issue #1702 · googleapis/java-pubsub
X Title: Pubsub: Unbounded retry forced when publishing with message ordering enabled · Issue #1702 · googleapis/java-pubsub
Description: Summary When publishing to pubsub with message ordering enabled, the library overrides the gRPC retry settings and forces unbounded retry. The application using this library is then unable to detect failures. The workaround is to add tim...
Open Graph Description: Summary When publishing to pubsub with message ordering enabled, the library overrides the gRPC retry settings and forces unbounded retry. The application using this library is then unable to detec...
X Description: Summary When publishing to pubsub with message ordering enabled, the library overrides the gRPC retry settings and forces unbounded retry. The application using this library is then unable to detec...
Opengraph URL: https://github.com/googleapis/java-pubsub/issues/1702
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Pubsub: Unbounded retry forced when publishing with message ordering enabled","articleBody":"#### Summary\r\n\r\nWhen publishing to pubsub with message ordering enabled, the library overrides the gRPC retry settings and forces unbounded retry. The application using this library is then unable to detect failures. The workaround is to add timeout when waiting for the returned future, but this makes the retry/timeout policy scattered and surprising to configure.\r\n\r\nThis is the code that enforces infinite retry.\r\nhttps://github.com/googleapis/java-pubsub/blob/main/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Publisher.java#L168 line 174 to line 180\r\n\r\nThe exact reason why the infinite retry does not eventually become successful is unclear. We have multiple random occurrences where applications running in a GKE cluster would stop publishing. In some instances, we had even waited for the application to retry for up to a week without success. Unfortunately we do not have a reliable way to trigger this type of failure and we do not have the low level gRPC logs when the failure happened.\r\n\r\nMy suggestion is to allow the library user to set a sane upper bound for retry, and let failures be propagated through the `onFailure` callback.\r\n\r\n#### Environment details\r\n\r\n1. API: Pubsub\r\n2. OS type and version: Ubuntu 22.04\r\n3. Java version: temurin-17.0.8\r\n4. version(s): google-cloud-pubsub-1.123.12\r\n\r\n#### Steps to reproduce\r\n\r\n 1. Enable message ordering in publisher\r\n 2. Publish messages\r\n 3. Simulate failure, such as network disconnect\r\n\r\n#### Code example\r\n\r\nBased on sample publish code in documentation.\r\n\r\n```java\r\n Publisher publisher =\r\n Publisher.newBuilder(topicName)\r\n // Sending messages to the same region ensures they are received in order\r\n // even when multiple publishers are used.\r\n .setEndpoint(\"us-east1-pubsub.googleapis.com:443\")\r\n .setEnableMessageOrdering(true)\r\n .build();\r\n\r\n try {\r\n Map\u003cString, String\u003e messages = new LinkedHashMap\u003cString, String\u003e();\r\n messages.put(\"message1\", \"key1\");\r\n // auto-generate many more messages here ...\r\n\r\n for (Map.Entry\u003cString, String\u003e entry : messages.entrySet()) {\r\n ByteString data = ByteString.copyFromUtf8(entry.getKey());\r\n PubsubMessage pubsubMessage =\r\n PubsubMessage.newBuilder().setData(data).setOrderingKey(entry.getValue()).build();\r\n ApiFuture\u003cString\u003e future = publisher.publish(pubsubMessage);\r\n\r\n // Add an asynchronous callback to handle publish success / failure.\r\n ApiFutures.addCallback(\r\n future,\r\n new ApiFutureCallback\u003cString\u003e() {\r\n\r\n // onFailure is never called, because the publisher will retry indefinitely\r\n\r\n @Override\r\n public void onFailure(Throwable throwable) {\r\n if (throwable instanceof ApiException) {\r\n ApiException apiException = ((ApiException) throwable);\r\n // Details on the API exception.\r\n System.out.println(apiException.getStatusCode().getCode());\r\n System.out.println(apiException.isRetryable());\r\n }\r\n System.out.println(\"Error publishing message : \" + pubsubMessage.getData());\r\n }\r\n\r\n @Override\r\n public void onSuccess(String messageId) {\r\n // Once published, returns server-assigned message ids (unique within the topic).\r\n System.out.println(pubsubMessage.getData() + \" : \" + messageId);\r\n }\r\n },\r\n MoreExecutors.directExecutor());\r\n }\r\n } finally {\r\n // When finished with the publisher, shutdown to free up resources.\r\n publisher.shutdown();\r\n publisher.awaitTermination(1, TimeUnit.MINUTES);\r\n }\r\n```\r\n\r\n#### Stack trace\r\n```\r\nNo stack trace because of infinite retry\r\n```\r\n\r\n#### External references such as API reference guides\r\n\r\n- https://cloud.google.com/pubsub/docs/publisher\r\n\r\n#### Any additional information below\r\n\r\n","author":{"url":"https://github.com/poernahi","@type":"Person","name":"poernahi"},"datePublished":"2023-08-17T17:09:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/1702/java-pubsub/issues/1702"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:289936ac-478e-50c1-f2e5-8ed420240057 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9F62:1F3B04:6B3E9B:87EDE3:6991353A |
| html-safe-nonce | 3d448057f2b69eeec56ce58b630f35885a24555b0ea435f10c4ecf3584bebda1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RjYyOjFGM0IwNDo2QjNFOUI6ODdFREUzOjY5OTEzNTNBIiwidmlzaXRvcl9pZCI6IjI1MzkyOTQ5Nzc4NjY2MDE1NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f518043b2f8d099d53f922719af128fbf4ed7413a31e7f163deb05214ead4dbb |
| hovercard-subject-tag | issue:1855387230 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/java-pubsub/1702/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ed59511fbce4ed878cbc14ec314768571792b9d1cb5dfcc82956315d611a7b4f/googleapis/java-pubsub/issues/1702 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ed59511fbce4ed878cbc14ec314768571792b9d1cb5dfcc82956315d611a7b4f/googleapis/java-pubsub/issues/1702 |
| og:image:alt | Summary When publishing to pubsub with message ordering enabled, the library overrides the gRPC retry settings and forces unbounded retry. The application using this library is then unable to detec... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | poernahi |
| hostname | github.com |
| expected-hostname | github.com |
| None | 42c603b9d642c4a9065a51770f75e5e27132fef0e858607f5c9cb7e422831a7b |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/java-pubsub git https://github.com/googleapis/java-pubsub.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 203461480 |
| octolytics-dimension-repository_nwo | googleapis/java-pubsub |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 203461480 |
| octolytics-dimension-repository_network_root_nwo | googleapis/java-pubsub |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 848bc6032dcc93a9a7301dcc3f379a72ba13b96e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width