pubsub: cap stream reconnect time#2409
pubsub: cap stream reconnect time#2409pongad merged 3 commits intogoogleapis:masterfrom pongad:max-recon
Conversation
Previously we exponentially grow stream reconnect backoff time without bound, so unlucky users will wait forever waiting for a connection. This commit caps the reconnect at 10s (the same as polling). Previously we only reset the polling time after the stream closes without error. This usually doesn't happen because the streams are long running and don't close until some error is encountered. This commit resets the polling time if we receive any response from the stream. Updates #2406.
|
@davidtorres Looking at this more, I'm not sure if this class is properly synchronized. Do we need a mutex around requestObserver? I think |
|
Additionally the Builder for the Subscriber should be fixed, so that the user can chosse between polling or streaming. See: https://github.com/GoogleCloudPlatform/google-cloud-java/blob/ce59d34fa59c66add4c8370f1ca760f127a91b56/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Subscriber.java#L607 (should be public) |
|
@Andy2003 The private access was intentional. We'd like to migrate to streaming exclusively. Do you have a use case that streaming does not solve? If there is, I think we should consider that a bug. |
|
A solution to work-around the current bug would be to switch back to pulling. But this is not possible, so the only choice was to downgrade to 0.21.1-beta. |
|
If you are running into this in production, I think the right answer is to roll back instead of forward. It does take some time for us to cut a new release so even with this PR merged, we might not be able to cut one immediately. That said, it might make sense, in the next release, to make this method public and |
|
@davidtorres is OOO this week FYI. I would be against marking deprecated, the message should be that StreamingPull is the new preferred API - the first users to upgrade to a new version will always be taking on some amount of risk, and I think rolling back makes more sense than keeping the old version of the code alive just in case there are bugs - we discuss more offline if you feel strongly. |
|
@mdietz94 I agree with you but wanted to bring others into the conversation since I don't want to be a dictator :) Would you like to review this change? Or should we wait for David? |
| long backoffMillis = channelReconnectBackoff.toMillis(); | ||
| channelReconnectBackoff = channelReconnectBackoff.plusMillis(backoffMillis); | ||
| long backoffMillis = channelReconnectBackoffMillis.get(); | ||
| long newBackoffMillis = backoffMillis*2; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@mdietz94 PTAL. The failing test seems to be coming from logging and unrelated to this change. Do you have any opinion about the potential race I called out earlier? |
|
I agree it looks like there could be a race, unless there is some other sort of guarantee that we won't try to ack while restarting a stream. I think a Mutex would definitely fix it, but maybe it's worth looking through the initial review, I didn't take part in it and maybe they discussed why this wouldn't e a problem then. If it isn't a race it definitely needs a comment explaining why. |
|
@mdietz94 I looked into this more. I'm almost certain there's a race. I'll merge this PR now and send out a fix separately. |
🤖 I have created a release *beep* *boop* --- ## [2.35.4](https://togithub.com/googleapis/java-spanner-jdbc/compare/v2.35.3...v2.35.4) (2026-03-04) ### Bug Fixes * Fix Column Type Name for PostgreSQL ARRAY types ([googleapis#2409](https://togithub.com/googleapis/java-spanner-jdbc/issues/2409)) ([cc95355](https://togithub.com/googleapis/java-spanner-jdbc/commit/cc9535517ac7a91b098e99ec53242663747bed63)) * Fix UTC<->Timezone conversion issue for DST start and end timestamp ([googleapis#2260](https://togithub.com/googleapis/java-spanner-jdbc/issues/2260)) ([a628fbc](https://togithub.com/googleapis/java-spanner-jdbc/commit/a628fbc2569af1eab47f56c2bafc6cbbbe7566c8)) ### Dependencies * Update dependency com.fasterxml.jackson.core:jackson-databind to v2.21.1 ([googleapis#2406](https://togithub.com/googleapis/java-spanner-jdbc/issues/2406)) ([b1a9cfd](https://togithub.com/googleapis/java-spanner-jdbc/commit/b1a9cfd087d43b8d4b8a9f563f77df96c303c9ca)) * Update dependency com.google.api.grpc:proto-google-cloud-trace-v1 to v2.85.0 ([googleapis#2395](https://togithub.com/googleapis/java-spanner-jdbc/issues/2395)) ([c0e7ac2](https://togithub.com/googleapis/java-spanner-jdbc/commit/c0e7ac257707f7c5b1a895bef325e99f0f2b2e71)) * Update dependency com.google.api.grpc:proto-google-cloud-trace-v1 to v2.86.0 ([googleapis#2407](https://togithub.com/googleapis/java-spanner-jdbc/issues/2407)) ([3f6e7fc](https://togithub.com/googleapis/java-spanner-jdbc/commit/3f6e7fc65d0c2f989dd83cb6b13196fb72278203)) * Update dependency com.google.cloud:google-cloud-spanner to v6.111.1 ([googleapis#2410](https://togithub.com/googleapis/java-spanner-jdbc/issues/2410)) ([644c081](https://togithub.com/googleapis/java-spanner-jdbc/commit/644c0816a1a061ca4c73fb0187dbcf57729d64c2)) * Update dependency com.google.cloud:google-cloud-spanner-bom to v6.111.1 ([googleapis#2411](https://togithub.com/googleapis/java-spanner-jdbc/issues/2411)) ([351a974](https://togithub.com/googleapis/java-spanner-jdbc/commit/351a974567edca6e387bb56d14ef09eb038cbfb5)) * Update dependency com.google.cloud:google-cloud-trace to v2.85.0 ([googleapis#2396](https://togithub.com/googleapis/java-spanner-jdbc/issues/2396)) ([2f93594](https://togithub.com/googleapis/java-spanner-jdbc/commit/2f9359434f25191e5db827c9fa2c33e6493e7650)) * Update dependency com.google.cloud:google-cloud-trace to v2.86.0 ([googleapis#2408](https://togithub.com/googleapis/java-spanner-jdbc/issues/2408)) ([2bedcba](https://togithub.com/googleapis/java-spanner-jdbc/commit/2bedcba91133e079829812c3dcdf88b7994caad4)) * Update dependency com.google.cloud:sdk-platform-java-config to v3.57.0 ([googleapis#2405](https://togithub.com/googleapis/java-spanner-jdbc/issues/2405)) ([fb80362](https://togithub.com/googleapis/java-spanner-jdbc/commit/fb803624c94d5b04c1212fb2c1765107b0e887a0)) * Update dependency net.bytebuddy:byte-buddy to v1.18.5 ([googleapis#2397](https://togithub.com/googleapis/java-spanner-jdbc/issues/2397)) ([f498b66](https://togithub.com/googleapis/java-spanner-jdbc/commit/f498b66202aec9bceedc7fb9ed4eb962dcfdad07)) * Update dependency net.bytebuddy:byte-buddy-agent to v1.18.5 ([googleapis#2398](https://togithub.com/googleapis/java-spanner-jdbc/issues/2398)) ([507c255](https://togithub.com/googleapis/java-spanner-jdbc/commit/507c255ba6a55e79855643c5c4143fd9d23f5a02)) * Update dependency org.springframework.boot:spring-boot to v4.0.3 ([googleapis#2403](https://togithub.com/googleapis/java-spanner-jdbc/issues/2403)) ([a2fbe8d](https://togithub.com/googleapis/java-spanner-jdbc/commit/a2fbe8d497d95940f1deaf1efc9dda7d2f913e45)) * Update dependency org.springframework.boot:spring-boot-starter-data-jdbc to v4.0.3 ([googleapis#2404](https://togithub.com/googleapis/java-spanner-jdbc/issues/2404)) ([e1ae535](https://togithub.com/googleapis/java-spanner-jdbc/commit/e1ae5353123477669fbe4e2efd1003ba5eaff6be)) * Update dependency org.springframework.boot:spring-boot-starter-parent to v3.5.11 ([googleapis#2402](https://togithub.com/googleapis/java-spanner-jdbc/issues/2402)) ([626096d](https://togithub.com/googleapis/java-spanner-jdbc/commit/626096d6428defed74e7c62f5810898c8f0f931b)) --- This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please).
Previously we exponentially grow stream reconnect backoff time
without bound, so unlucky users will wait forever waiting for
a connection.
This commit caps the reconnect at 10s (the same as polling).
Previously we only reset the polling time after the stream closes
without error. This usually doesn't happen because the streams are
long running and don't close until some error is encountered.
This commit resets the polling time if we receive any response
from the stream.
Updates #2406.