-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrap the managed worker thread pool to disallow shutdown on prod mode #43268
Merged
ozangunalp
merged 1 commit into
quarkusio:main
from
ozangunalp:worker_pool_disallow_shutdown
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
core/runtime/src/main/java/io/quarkus/runtime/util/ForwardingScheduledExecutorService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.quarkus.runtime.util; | ||
|
||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.ScheduledFuture; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Forwards all method calls to the scheduled executor service returned from the {@link #delegate()} method. Only non-default | ||
* methods | ||
* declared on the {@link ScheduledExecutorService} interface are forwarded. | ||
*/ | ||
public abstract class ForwardingScheduledExecutorService extends ForwardingExecutorService implements ScheduledExecutorService { | ||
|
||
protected abstract ScheduledExecutorService delegate(); | ||
|
||
@Override | ||
public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { | ||
return delegate().schedule(command, delay, unit); | ||
} | ||
|
||
@Override | ||
public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) { | ||
return delegate().schedule(callable, delay, unit); | ||
} | ||
|
||
@Override | ||
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) { | ||
return delegate().scheduleAtFixedRate(command, initialDelay, period, unit); | ||
} | ||
|
||
@Override | ||
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) { | ||
return delegate().scheduleWithFixedDelay(command, initialDelay, delay, unit); | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
core/runtime/src/main/java/io/quarkus/runtime/util/NoopShutdownScheduledExecutorService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package io.quarkus.runtime.util; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
/** | ||
* Forwards all method calls to the scheduled executor service returned from the {@link #delegate()} method. | ||
* Does not allow shutdown | ||
*/ | ||
public class NoopShutdownScheduledExecutorService extends ForwardingScheduledExecutorService { | ||
|
||
private static final Logger LOG = Logger.getLogger(NoopShutdownScheduledExecutorService.class); | ||
|
||
private final ScheduledExecutorService delegate; | ||
|
||
public NoopShutdownScheduledExecutorService(final ScheduledExecutorService delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
protected ScheduledExecutorService delegate() { | ||
return delegate; | ||
} | ||
|
||
@Override | ||
public boolean isShutdown() { | ||
// managed executors are never shut down from the application's perspective | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isTerminated() { | ||
// managed executors are never shut down from the application's perspective | ||
return false; | ||
} | ||
|
||
@Override | ||
public void shutdown() { | ||
LOG.debug("shutdown() not allowed on managed executor service"); | ||
} | ||
|
||
@Override | ||
public List<Runnable> shutdownNow() { | ||
LOG.debug("shutdownNow() not allowed on managed executor service"); | ||
return List.of(); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
...rtx/deployment/src/test/java/io/quarkus/vertx/deployment/VertxWorkerPoolShutdownTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.quarkus.vertx.deployment; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.event.Observes; | ||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.runtime.StartupEvent; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.vertx.core.Future; | ||
import io.vertx.core.Vertx; | ||
|
||
public class VertxWorkerPoolShutdownTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(MyBean.class)); | ||
|
||
@Test | ||
public void test() { | ||
MyBean bean = Arc.container().instance(MyBean.class).get(); | ||
Assertions.assertTrue(bean.isOk()); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class MyBean { | ||
|
||
@Inject | ||
Vertx vertx; | ||
|
||
@Inject | ||
ExecutorService executorService; | ||
|
||
boolean ok; | ||
|
||
public boolean isOk() { | ||
return ok; | ||
} | ||
|
||
public void init(@Observes StartupEvent ev) { | ||
executorService.shutdownNow(); | ||
ozangunalp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
((io.vertx.core.impl.ContextInternal) vertx.getOrCreateContext()).workerPool().executor().shutdownNow(); | ||
Future<Boolean> ok1 = vertx.executeBlocking(() -> true); | ||
ok = ok1.toCompletionStage().toCompletableFuture().join(); | ||
} | ||
} | ||
} |
39 changes: 0 additions & 39 deletions
39
...ertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/NoopShutdownExecutorService.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, isn't the Vert.x worker thread pool backed by this very
ExecutorService
in the prod mode? If so, then we could remove the vertx-specific stuff for the prod mode here: https://github.com/quarkusio/quarkus/blob/main/extensions/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/VertxCoreRecorder.java#L110There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let's try to simplify the code! Except that we don't have a test for this. I guess that we could at least try to run the reproducer from #16833 manually?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let me remove the draft to run the existing test suite. I can also reproduce with #43228.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest we allow the shutdown only on dev mode. It'd be better if tests were closer to prod.