fix(pubsub/v2): skip stream keep-alive when using binary emulator#14359
fix(pubsub/v2): skip stream keep-alive when using binary emulator#14359shairoth12 wants to merge 3 commits intogoogleapis:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request modifies the PubSub iterator to skip dead-stream detection when the PUBSUB_EMULATOR_HOST environment variable is set, preventing unnecessary stream teardowns when using the emulator. A critical deadlock issue was identified in the implementation: the WaitGroup is incremented unconditionally, but the goroutine responsible for decrementing it is skipped when the emulator is active, which will cause the iterator's stop method to hang indefinitely.
removing review in favor of emulator change
Problem
Fixes #14358
pubsub/v2v2.5.0 introduced dead-stream detection (streamKeepAliveHandler) that sends periodic keep-alive pings and tears down the stream if the server doesn't respond. The binary PubSub emulator (gcloud beta emulators pubsub start) silently discards these pings, causing repeated false stream teardowns and 15–45s message delivery delays.Solution
Skip
streamKeepAliveHandlerwhenPUBSUB_EMULATOR_HOSTis set — the same env var already used to configure insecure credentials for the emulator. Tickers are still created unconditionally to avoid nil-guard changes throughout the codebase; they simply tick into the void.Changes
iterator.go: gatego it.streamKeepAliveHandler()behindos.Getenv("PUBSUB_EMULATOR_HOST") == ""iterator_test.go: addTestStreamingPullKeepAlive_Disabled— mirrors the existing reconnect test with aggressive intervals andprotocolVersion=0, but assertsopenCount == 1(no reconnects) when the env var is set