Skip to content

Commit

Permalink
Merge pull request #44620 from gsmet/do-not-honor-timeout-in-dev-mode
Browse files Browse the repository at this point in the history
Do not honor shutdown timeout/delay in dev mode
  • Loading branch information
geoand authored Nov 22, 2024
2 parents d3e99ba + 6ccf8b7 commit fcf042c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.deployment.shutdown;

import io.quarkus.runtime.LaunchMode;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
Expand All @@ -19,4 +20,8 @@ public interface ShutdownBuildTimeConfig {
*/
@WithDefault("false")
boolean delayEnabled();

default boolean isDelayEnabled() {
return delayEnabled() && LaunchMode.current() != LaunchMode.DEVELOPMENT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public class ShutdownListenerBuildStep {
void setupShutdown(List<ShutdownListenerBuildItem> listeners, ShutdownBuildTimeConfig shutdownBuildTimeConfig,
ShutdownRecorder recorder) {
recorder.setListeners(listeners.stream().map(ShutdownListenerBuildItem::getShutdownListener).toList(),
shutdownBuildTimeConfig.delayEnabled());
shutdownBuildTimeConfig.isDelayEnabled());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.time.Duration;
import java.util.Optional;

import io.quarkus.runtime.LaunchMode;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
Expand Down Expand Up @@ -32,11 +33,13 @@ public interface ShutdownConfig {
*/
Optional<Duration> delay();

default boolean isShutdownTimeoutSet() {
return timeout().isPresent() && timeout().get().toMillis() > 0;
default boolean isTimeoutEnabled() {
return timeout().isPresent() && timeout().get().toMillis() > 0
&& LaunchMode.current() != LaunchMode.DEVELOPMENT;
}

default boolean isDelaySet() {
return delay().isPresent() && delay().get().toMillis() > 0;
default boolean isDelayEnabled() {
return delay().isPresent() && delay().get().toMillis() > 0
&& LaunchMode.current() != LaunchMode.DEVELOPMENT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static void executePreShutdown() throws InterruptedException {
}

private static void waitForDelay() {
if (delayEnabled && shutdownConfig.isDelaySet()) {
if (delayEnabled && shutdownConfig.isDelayEnabled()) {
try {
Thread.sleep(shutdownConfig.delay().get().toMillis());
} catch (InterruptedException e) {
Expand All @@ -64,7 +64,7 @@ private static void executeShutdown() throws InterruptedException {
for (ShutdownListener i : shutdownListeners) {
i.shutdown(new LatchShutdownNotification(shutdown));
}
if (shutdownConfig.isShutdownTimeoutSet()
if (shutdownConfig.isTimeoutEnabled()
&& !shutdown.await(shutdownConfig.timeout().get().toMillis(), TimeUnit.MILLISECONDS)) {
log.error("Timed out waiting for graceful shutdown, shutting down anyway.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ public void handle(RoutingContext routingContext) {

boolean quarkusWrapperNeeded = false;

if (shutdownConfig.isShutdownTimeoutSet()) {
if (shutdownConfig.isTimeoutEnabled()) {
gracefulShutdownFilter.next(root);
root = gracefulShutdownFilter;
quarkusWrapperNeeded = true;
Expand Down

0 comments on commit fcf042c

Please sign in to comment.