vert-x3 / vertx-rabbitmq-client

Vert.x RabbitMQ Service
Apache License 2.0
73 stars 64 forks source link

Fix bug: stackoverflow error after automatic reconnection. #142

Closed Neway13 closed 3 years ago

Neway13 commented 3 years ago

Motivation:

The StackOverflowError occurred after automatic reconnection 2,000 times

java.lang.StackOverflowError: null
    at io.vertx.core.impl.AbstractContext.isRunningOnContext(AbstractContext.java:41) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.FutureBase.emitSuccess(FutureBase.java:50) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.FutureImpl.tryComplete(FutureImpl.java:211) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.PromiseImpl.tryComplete(PromiseImpl.java:23) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.PromiseImpl.onSuccess(PromiseImpl.java:49) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.FutureBase.emitSuccess(FutureBase.java:60) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.FutureImpl.tryComplete(FutureImpl.java:211) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.Composition$1.onSuccess(Composition.java:62) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.FutureBase.emitSuccess(FutureBase.java:60) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.FutureImpl.tryComplete(FutureImpl.java:211) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.PromiseImpl.tryComplete(PromiseImpl.java:23) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.PromiseImpl.onSuccess(PromiseImpl.java:49) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.FutureBase.emitSuccess(FutureBase.java:60) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.FutureImpl.tryComplete(FutureImpl.java:211) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.Composition$1.onSuccess(Composition.java:62) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.FutureBase.emitSuccess(FutureBase.java:60) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.FutureImpl.tryComplete(FutureImpl.java:211) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.PromiseImpl.tryComplete(PromiseImpl.java:23) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.PromiseImpl.onSuccess(PromiseImpl.java:49) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.FutureBase.emitSuccess(FutureBase.java:60) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.FutureImpl.tryComplete(FutureImpl.java:211) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.Composition$1.onSuccess(Composition.java:62) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.FutureBase.emitSuccess(FutureBase.java:60) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.FutureImpl.tryComplete(FutureImpl.java:211) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.PromiseImpl.tryComplete(PromiseImpl.java:23) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    at io.vertx.core.impl.future.PromiseImpl.onSuccess(PromiseImpl.java:49) ~[vertx-core-4.2.0-20211009.081319-114.jar:4.2.0-SNAPSHOT]
    ......

I can reproduce the stackoverflow error by following steps :

  1. The client connects to the MQ server using the following reconnection configuration:
    RabbitMQOptions options = new RabbitMQOptions();
    options.setAutomaticRecoveryEnabled(false);
    options.setReconnectAttempts(Integer.MAX_VALUE);
    options.setReconnectInterval(50);  // To reproduce the stackoverflow error quickly.
  2. Stop the MQ server, the client starts to reconnect automatically.
  3. After the client failed to reconnect for 2000 times, I restart the MQ server.

The client should reconnect successfully, but the program threw a stackoverflow error. Because every time the client tries to reconnect, a new promise is created here. Nesting promises lead to the stackoverflow error. In order to solve this problem, only the same pomise is used in the process of reconnecting.

Neway13 commented 3 years ago

@vietj It seems to be a CI problem. 😵 image

vietj commented 3 years ago

it seems to fail on JDK 17 but fine on 8, I reran tests but it might be due to a TLS issue with 17 tests