From b42d9f42a58bcb12f3fc353febcc1a4e9d4b4c26 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Mon, 27 Feb 2017 12:01:18 +1100 Subject: [PATCH] properly stop MessageDispatcher if Subscriber fails When PollingSubscriberConnection fails, it calls `notifyFailed`. Subscriber listens to this failure and stops all connections before failing itself. Stopping connections is implemented with `stopAsync`. The problem is with the connection that originally failed. Since it has already entered the FAILED state, it cannot be stopped by `stopAsync`. Consequently, this leaks a MessageDispatcher. This commit makes the connection explicitly stop itself before notifying the Subscriber that it has failed. --- .../google/cloud/pubsub/spi/v1/PollingSubscriberConnection.java | 1 + 1 file changed, 1 insertion(+) diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PollingSubscriberConnection.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PollingSubscriberConnection.java index 455bfbd37ba8..3bbf8ed02467 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PollingSubscriberConnection.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PollingSubscriberConnection.java @@ -185,6 +185,7 @@ public void run() { TimeUnit.MILLISECONDS); return; } + messageDispatcher.stop(); notifyFailed(cause); } });