Skip to content

Commit 6c4d83e

Browse files
committed
Conditional closing of curated application
Also reverse workaround for over-eager closing of H2 database, since this fix is the proper solution.
1 parent 39c187c commit 6c4d83e

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

core/deployment/src/main/java/io/quarkus/runner/bootstrap/StartupActionImpl.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,15 @@ public void close() throws IOException {
340340
log.error("Failed to run close task", t);
341341
}
342342
}
343-
if (curatedApplication.getQuarkusBootstrap().getMode() == QuarkusBootstrap.Mode.TEST &&
344-
!curatedApplication.getQuarkusBootstrap().isAuxiliaryApplication()) {
345-
//for tests, we just always shut down the curated application, as it is only used once
346-
//dev mode might be about to restart, so we leave it
347-
curatedApplication.close();
343+
// This will read the state of the curated application at the time of closing;
344+
// If the caller of close knows that the 'next' application shares a curated application, it can set eligible for reuse to true
345+
if (!curatedApplication.isEligibleForReuse()) {
346+
if (curatedApplication.getQuarkusBootstrap().getMode() == QuarkusBootstrap.Mode.TEST
347+
&& !curatedApplication.getQuarkusBootstrap().isAuxiliaryApplication()) {
348+
//for tests, we just always shut down the curated application, as it is only used once
349+
//dev mode might be about to restart, so we leave it
350+
curatedApplication.close();
351+
}
348352
}
349353
}
350354
}

extensions/devservices/h2/src/main/java/io/quarkus/devservices/h2/deployment/H2DevServicesProcessor.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,12 @@ public void close() throws IOException {
8484
} catch (SQLException t) {
8585
t.printStackTrace();
8686
}
87-
// TODO Yes, this is a port leak
88-
// The good news is that because it's an in-memory database, it will get shut down
89-
// when the JVM stops. Nonetheless, this clearly is not ok, and needs
90-
// a fix so that we do not start databases in the augmentation phase
91-
// TODO remove this when #45786 and #45785 are done
92-
final boolean hackPendingDeferredDevServiceStart = true;
93-
if (!hackPendingDeferredDevServiceStart) {
94-
tcpServer.stop();
95-
LOG.info("Dev Services for H2 shut down; server status: " + tcpServer.getStatus());
96-
97-
}
98-
// End of #45786 and #45785 workaround
99-
87+
tcpServer.stop();
88+
LOG.info("Dev Services for H2 shut down; server status: " + tcpServer.getStatus());
89+
} else {
90+
LOG.info(
91+
"Dev Services for H2 was NOT shut down as it appears it was down already; server status: "
92+
+ tcpServer.getStatus());
10093
}
10194
}
10295
});

independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/CuratedApplication.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public class CuratedApplication implements Serializable, AutoCloseable {
6868
final ApplicationModel appModel;
6969

7070
final AtomicInteger runtimeClassLoaderCount = new AtomicInteger();
71+
private boolean eligibleForReuse = false;
7172

7273
CuratedApplication(QuarkusBootstrap quarkusBootstrap, CurationResult curationResult,
7374
ConfiguredClassLoading configuredClassLoading) {
@@ -77,6 +78,10 @@ public class CuratedApplication implements Serializable, AutoCloseable {
7778
this.configuredClassLoading = configuredClassLoading;
7879
}
7980

81+
public void setEligibleForReuse(boolean eligible) {
82+
this.eligibleForReuse = eligible;
83+
}
84+
8085
public boolean isFlatClassPath() {
8186
return configuredClassLoading.isFlatTestClassPath();
8287
}
@@ -459,6 +464,10 @@ public void close() {
459464
augmentationElements.clear();
460465
}
461466

467+
public boolean isEligibleForReuse() {
468+
return eligibleForReuse;
469+
}
470+
462471
/**
463472
* TODO: Fix everything in the universe to do loading properly
464473
*

test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,16 @@ private QuarkusTestExtensionState ensureStarted(ExtensionContext extensionContex
616616
currentJUnitTestClass = extensionContext.getRequiredTestClass();
617617
}
618618
boolean isNewApplication = isNewApplication(state, extensionContext.getRequiredTestClass());
619+
620+
QuarkusClassLoader cl = (QuarkusClassLoader) extensionContext.getRequiredTestClass().getClassLoader();
621+
622+
CuratedApplication curatedApplication = runningQuarkusApplication != null
623+
? ((QuarkusClassLoader) runningQuarkusApplication.getClassLoader())
624+
.getCuratedApplication()
625+
: null;
626+
boolean isSameCuratedApplication = cl.getCuratedApplication() == curatedApplication;
627+
cl.getCuratedApplication().setEligibleForReuse(isSameCuratedApplication);
628+
619629
// TODO if classes are misordered, say because someone overrode the ordering, and there are profiles or resources,
620630
// we could try to start and application which has already been started, and fail with a mysterious error about
621631
// null shutdown contexts; we should try and detect that case, and give a friendlier error message

0 commit comments

Comments
 (0)