Skip to content

Commit 3cb7837

Browse files
authored
fix: set restart monitor before checking for dev server connection (#17157)
If hot reload is enabled, e.g. with Spring Dev Tools, during Java server restart the check for active dev-server connection may temporarily fail because the dev-server is restarting. This change finds and sets the currently active restart monitor before checking for dev-server connection, so that the check will wait for a potential restart to complete.
1 parent ad2ed55 commit 3cb7837

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

vaadin-dev-server/src/main/java/com/vaadin/base/devserver/AbstractDevServerRunner.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ private void runOnFutureComplete() {
176176
}
177177

178178
void doStartDevModeServer() throws ExecutionFailedException {
179+
waitForRestart = DevServerOutputTracker.activeServerRestartGuard();
180+
if (waitForRestart != null) {
181+
getLogger().debug("RestartMonitor is active");
182+
}
179183
// If port is defined, means that the dev server is already running
180184
if (port > 0) {
181185
if (!checkConnection()) {
@@ -537,10 +541,6 @@ private void reuseExistingPort(int port) {
537541
// Save running port for next usage
538542
saveRunningDevServerPort();
539543
watchDog.set(null);
540-
waitForRestart = DevServerOutputTracker.activeServerRestartGuard();
541-
if (waitForRestart != null) {
542-
getLogger().debug("RestartMonitor is active");
543-
}
544544
}
545545

546546
private void saveRunningDevServerPort() {

vaadin-dev-server/src/test/java/com/vaadin/base/devserver/RestartMonitorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void waitForServerReady_serverReady_notBlocking()
4040
CompletableFuture.runAsync(() -> simulateTask(latch));
4141
Assert.assertTrue(
4242
"Not restarting, execution should not have been blocked",
43-
latch.await(5, TimeUnit.MILLISECONDS));
43+
latch.await(10, TimeUnit.MILLISECONDS));
4444
}
4545

4646
@Test

0 commit comments

Comments
 (0)