Skip to content

Commit b4f8ec5

Browse files
authored
pubsub: eventually stop polling after termination (googleapis#2113)
Update googleapis#2103. This does not completely fix the problem. If an RPC is started before the shutdown, the RPC won't be canceled. Depending on how the channels and executors are set up, messages in the said RPCs might be lease-extended. With this PR, at least we're not polling forever anymore.
1 parent 65d5aad commit b4f8ec5

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PollingSubscriberConnection.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ protected void doStop() {
127127
}
128128

129129
private void pullMessages(final Duration backoff) {
130+
if (!isAlive()) {
131+
return;
132+
}
130133
ListenableFuture<PullResponse> pullResult =
131134
stub.withDeadlineAfter(DEFAULT_TIMEOUT.toMillis(), TimeUnit.MILLISECONDS)
132135
.pull(
@@ -201,7 +204,9 @@ public void run() {
201204
}
202205

203206
private boolean isAlive() {
204-
return state() == State.RUNNING || state() == State.STARTING;
207+
// Read state only once. Because of threading, different calls can give different results.
208+
State state = state();
209+
return state == State.RUNNING || state == State.STARTING;
205210
}
206211

207212
@Override

0 commit comments

Comments
 (0)