Skip to content

Commit dc6b158

Browse files
Merge pull request #4101 from gastaldi/fix_vertx
Fixed Shutdown in progress exception while destroying Quarkus app
2 parents bc67997 + 2f70108 commit dc6b158

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

extensions/vertx-core/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,13 @@ public class VertxCoreRecorder {
3636

3737
public static final String ENABLE_JSON = "quarkus-internal.vertx.enabled-json";
3838

39-
static volatile Supplier<Vertx> vertx;
39+
static volatile VertxSupplier vertx;
4040
//temporary vertx instance to work around a JAX-RS problem
4141
static volatile Vertx webVertx;
4242

4343
public Supplier<Vertx> configureVertx(BeanContainer container, VertxConfiguration config,
4444
LaunchMode launchMode, ShutdownContext shutdown) {
45-
vertx = new Supplier<Vertx>() {
46-
47-
Vertx v;
48-
49-
@Override
50-
public synchronized Vertx get() {
51-
if (v == null) {
52-
v = initialize(config);
53-
}
54-
return v;
55-
}
56-
};
57-
45+
vertx = new VertxSupplier(config);
5846
VertxCoreProducer producer = container.instance(VertxCoreProducer.class);
5947
producer.initialize(vertx);
6048
if (launchMode != LaunchMode.DEVELOPMENT) {
@@ -162,10 +150,10 @@ private static VertxOptions convertToVertxOptions(VertxConfiguration conf) {
162150
}
163151

164152
void destroy() {
165-
if (vertx != null) {
153+
if (vertx != null && vertx.v != null) {
166154
CountDownLatch latch = new CountDownLatch(1);
167155
AtomicReference<Throwable> problem = new AtomicReference<>();
168-
vertx.get().close(ar -> {
156+
vertx.v.close(ar -> {
169157
if (ar.failed()) {
170158
problem.set(ar.cause());
171159
}
@@ -303,7 +291,7 @@ public Supplier<EventLoopGroup> bossSupplier() {
303291
return new Supplier<EventLoopGroup>() {
304292
@Override
305293
public EventLoopGroup get() {
306-
return ((VertxImpl) vertx).getAcceptorEventLoopGroup();
294+
return ((VertxImpl) vertx.get()).getAcceptorEventLoopGroup();
307295
}
308296
};
309297
}
@@ -316,4 +304,21 @@ public EventLoopGroup get() {
316304
}
317305
};
318306
}
307+
308+
static class VertxSupplier implements Supplier<Vertx> {
309+
final VertxConfiguration config;
310+
Vertx v;
311+
312+
VertxSupplier(VertxConfiguration config) {
313+
this.config = config;
314+
}
315+
316+
@Override
317+
public synchronized Vertx get() {
318+
if (v == null) {
319+
v = initialize(config);
320+
}
321+
return v;
322+
}
323+
}
319324
}

extensions/vertx-core/runtime/src/test/java/io/quarkus/vertx/core/runtime/VertxCoreProducerTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,7 @@ public void shouldNotFailWithDefaultConfig() {
5454
configuration.workerPoolSize = 10;
5555
configuration.warningExceptionTime = Duration.ofSeconds(1);
5656
configuration.internalBlockingPoolSize = 5;
57-
VertxCoreRecorder.vertx = new Supplier<Vertx>() {
58-
@Override
59-
public Vertx get() {
60-
return VertxCoreRecorder.initialize(configuration);
61-
}
62-
};
57+
VertxCoreRecorder.vertx = new VertxCoreRecorder.VertxSupplier(configuration);
6358
producer.initialize(VertxCoreRecorder.vertx);
6459
verifyProducer();
6560
}

0 commit comments

Comments
 (0)