GoogleCloudPlatform / GoogleCloudPlatform/spring-cloud-gcp

PubSubReactiveFactory keeps messages in flight on shutdown

Open
#649 2 comments 0 reactions 0 assignees View on GitHub
priority: p3 pubsub type: enhancement
Dominant language
Java
Stars
551
Forks
349
Avg merge
1d 13h
Merged PRs (30d)
14

Description

Current implementation of the `PubSubReactiveFactory` does a `pullAsync` in the `backpressurePull`. Problem is that this call is async and when the pipeline is shutdown there may still be a call in flight. When this call completes and the callback notices that the `sink.isCancelled`, the payload is ignored. This leads to messages hitting the deadline of the ack period when restarting (scaling down, redeploy, etc) the application. Using auto scaling this happens a lot to us.

BTW the pipeline is shutdown with a flag which is set upon spring shutdown pre-notification, instead of calling the `dispose()` function. This to make sure that we would handle all in flight messages before shutting down, as opposed to cancelling outstanding jobs.

```kotlin
val shutdown = AtomicBoolean(false)
pubSubReactiveFactory.poll("topic", 100)
.takeUntil { shutdown.get() }
.flatMap { ... }
.subscribeOn(Schedulers.parallel())
.subscribe()
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.