File tree Expand file tree Collapse file tree
google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1 Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -243,6 +243,12 @@ public void close() {
243243 throw new IllegalStateException (e );
244244 }
245245
246+ // When started, connections submit tasks to the executor.
247+ // These tasks must finish before the connections can declare themselves running.
248+ // If we have a single-thread executor and call startPollingConnections from the
249+ // same executor, it will deadlock: the thread will be stuck waiting for connections
250+ // to start but cannot start the connections.
251+ // For this reason, we spawn a dedicated thread. Starting subscriber should be rare.
246252 new Thread (new Runnable () {
247253 @ Override
248254 public void run () {
@@ -395,6 +401,8 @@ private void startConnections(
395401 List <? extends ApiService > connections , final ApiService .Listener connectionsListener ) {
396402 for (ApiService subscriber : connections ) {
397403 subscriber .addListener (connectionsListener , executor );
404+ // Starting each connection submits a blocking task to the executor.
405+ // We start connections one at a time to avoid swamping executor with blocking tasks.
398406 subscriber .startAsync ().awaitRunning ();
399407 }
400408 }
You can’t perform that action at this time.
0 commit comments