Skip to content

quarkus.thread-pool.shutdown-interrupt is not respected #49733

@dgaffuri

Description

@dgaffuri

Describe the bug

When shutting down the application, runnable submitted through ManagedExecutor are interrupted before the configured timeout.

This is because the shutdown task runnable created in io.quarkus.runtime.ExecutorRecorder has a bug in computation of time remaining before interruption.

long start = System.nanoTime();
int loop = 1;
for (;;) {
    // This log can be very useful when debugging problems
    log.debugf("loop: %s, remaining: %s, intervalRemaining: %s, interruptRemaining: %s", loop++, remaining,
            intervalRemaining, interruptRemaining);
    try {
        if (!executor.awaitTermination(Math.min(remaining, intervalRemaining), TimeUnit.NANOSECONDS)) {
            long elapsed = System.nanoTime() - start;
            intervalRemaining -= elapsed;
            remaining -= elapsed;
            interruptRemaining -= elapsed;

Time elapsed since loop start is cumulated and subtracted from *remaining variables at each iteration, but should be removed from the initial values.

Expected behavior

Submitted runnable should be terminated after 60s

Actual behavior

Submitted runnable is interrupted after about 11s

How to Reproduce?

Build and run the attached sample project with

  1. ./mvnw clean package
  2. java -Dquarkus.thread-pool.shutdown-check-interval=1s -Dquarkus.thread-pool.shutdown-interrupt=60s '-Dquarkus.log.category."io.quarkus.thread-pool".level=DEBUG' -jar target/quarkus-app/quarkus-run.jar

sample.zip

Output of uname -a or ver

Darwin Mac.local 24.6.0 Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:40 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6041 arm64

Output of java -version

openjdk version "21.0.8" 2025-07-15

Quarkus version or git rev

3.25.4

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.9 (8e8579a9e76f7d015ee5ec7bfcdc97d260186937)

Additional information

Execution logs:

2025-08-27 15:44:05,925 INFO [io.quarkus] (main) sample 1.0.0-SNAPSHOT on JVM (powered by Quarkus 3.25.4) started in 0.275s. Listening on: http://0.0.0.0:8080
2025-08-27 15:44:05,929 INFO [io.quarkus] (main) Profile prod activated.
2025-08-27 15:44:05,929 INFO [io.quarkus] (main) Installed features: [cdi, rest, smallrye-context-propagation, vertx]
2025-08-27 15:44:05,943 DEBUG [io.qua.thread-pool] (main) loop: 1, remaining: 60000000000, intervalRemaining: 1000000000, interruptRemaining: 60000000000
2025-08-27 15:44:06,947 INFO [io.qua.thread-pool] (main) Awaiting thread pool shutdown; 1 thread(s) running
2025-08-27 15:44:06,961 DEBUG [io.qua.thread-pool] (main) loop: 2, remaining: 58995483041, intervalRemaining: 1000000000, interruptRemaining: 58995483041
2025-08-27 15:44:07,963 INFO [io.qua.thread-pool] (main) Awaiting thread pool shutdown; 1 thread(s) running
2025-08-27 15:44:07,965 DEBUG [io.qua.thread-pool] (main) loop: 3, remaining: 56975227832, intervalRemaining: 1000000000, interruptRemaining: 56975227832
2025-08-27 15:44:08,968 INFO [io.qua.thread-pool] (main) Awaiting thread pool shutdown; 1 thread(s) running
2025-08-27 15:44:08,969 DEBUG [io.qua.thread-pool] (main) loop: 4, remaining: 53949740040, intervalRemaining: 1000000000, interruptRemaining: 53949740040
2025-08-27 15:44:09,973 INFO [io.qua.thread-pool] (main) Awaiting thread pool shutdown; 1 thread(s) running
2025-08-27 15:44:09,975 DEBUG [io.qua.thread-pool] (main) loop: 5, remaining: 49919139081, intervalRemaining: 1000000000, interruptRemaining: 49919139081
2025-08-27 15:44:10,980 INFO [io.qua.thread-pool] (main) Awaiting thread pool shutdown; 1 thread(s) running
2025-08-27 15:44:10,981 DEBUG [io.qua.thread-pool] (main) loop: 6, remaining: 44881490706, intervalRemaining: 1000000000, interruptRemaining: 44881490706
2025-08-27 15:44:11,984 INFO [io.qua.thread-pool] (main) Awaiting thread pool shutdown; 1 thread(s) running
2025-08-27 15:44:11,985 DEBUG [io.qua.thread-pool] (main) loop: 7, remaining: 38840055581, intervalRemaining: 1000000000, interruptRemaining: 38840055581
2025-08-27 15:44:12,990 INFO [io.qua.thread-pool] (main) Awaiting thread pool shutdown; 1 thread(s) running
2025-08-27 15:44:12,991 DEBUG [io.qua.thread-pool] (main) loop: 8, remaining: 31792704622, intervalRemaining: 1000000000, interruptRemaining: 31792704622
2025-08-27 15:44:13,993 INFO [io.qua.thread-pool] (main) Awaiting thread pool shutdown; 1 thread(s) running
2025-08-27 15:44:13,994 DEBUG [io.qua.thread-pool] (main) loop: 9, remaining: 23742474455, intervalRemaining: 1000000000, interruptRemaining: 23742474455
2025-08-27 15:44:14,995 INFO [io.qua.thread-pool] (main) Awaiting thread pool shutdown; 1 thread(s) running
2025-08-27 15:44:14,997 DEBUG [io.qua.thread-pool] (main) loop: 10, remaining: 14690113038, intervalRemaining: 1000000000, interruptRemaining: 14690113038
2025-08-27 15:44:16,000 INFO [io.qua.thread-pool] (main) Awaiting thread pool shutdown; 1 thread(s) running
2025-08-27 15:44:16,001 DEBUG [io.qua.thread-pool] (main) loop: 11, remaining: 4632462954, intervalRemaining: 1000000000, interruptRemaining: 4632462954
2025-08-27 15:44:17,005 INFO [sam.GreetingResource] (executor-thread-1) interrupted
2025-08-27 15:44:17,005 WARN [io.qua.thread-pool] (main) Thread pool shutdown failed: -1 threads still running
2025-08-27 15:44:17,007 INFO [io.quarkus] (main) sample stopped in 11.077s

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions