Skip to content

fix(pubsub/v2): skip stream keep-alive when using binary emulator#14359

Open
shairoth12 wants to merge 3 commits intogoogleapis:mainfrom
shairoth12:disable-pubsub-emulator-keepalive
Open

fix(pubsub/v2): skip stream keep-alive when using binary emulator#14359
shairoth12 wants to merge 3 commits intogoogleapis:mainfrom
shairoth12:disable-pubsub-emulator-keepalive

Conversation

@shairoth12
Copy link
Copy Markdown

Problem

Fixes #14358

pubsub/v2 v2.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 streamKeepAliveHandler when PUBSUB_EMULATOR_HOST is 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: gate go it.streamKeepAliveHandler() behind os.Getenv("PUBSUB_EMULATOR_HOST") == ""
  • iterator_test.go: add TestStreamingPullKeepAlive_Disabled — mirrors the existing reconnect test with aggressive intervals and protocolVersion=0, but asserts openCount == 1 (no reconnects) when the env var is set

@shairoth12 shairoth12 requested review from a team as code owners April 6, 2026 11:11
@product-auto-label product-auto-label bot added the api: pubsub Issues related to the Pub/Sub API. label Apr 6, 2026
@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 6, 2026

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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pubsub/v2/iterator.go
hongalex
hongalex previously approved these changes Apr 6, 2026
@hongalex hongalex added the kokoro:run Add this label to force Kokoro to re-run the tests. label Apr 6, 2026
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Apr 6, 2026
Comment thread pubsub/v2/iterator.go Outdated
@hongalex hongalex added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 7, 2026
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 7, 2026
@hongalex hongalex dismissed their stale review April 17, 2026 21:34

removing review in favor of emulator change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: pubsub Issues related to the Pub/Sub API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pubsub/v2: StreamingPull keep-alive causes repeated stream teardowns when using the binary emulator

3 participants