Comments (5)
@ochedru Thanks for reporting this!
I've also reproduced the bug with the SimpleServerFactory
and enableVirtualThreads
set to true
.
from dropwizard.
@cty123 The issue exists due to the presence of the enableVirtualThreads
flag. This flag is present in the versions 3.x, 4.x and 5.x. After we have a solution, this will be merged to all those branches.
from dropwizard.
When using virtual threads, an AsynchronousCloseException
is thrown to Jetty's AbstractConnector
class while waiting to accept connections. When overriding the Dropwizard application's main
method and calling Server.join()
there, the issue doesn't occur. So it seems like the thread pool gets closed when the connection handling isn't done by blocking platform threads.
I'll investigate, if we can/should call Server.join()
on the Dropwizard side or if we shouldn't do this because it happens inside the CLI execution.
from dropwizard.
I had the same issue, and here is what I have found out. Typically this is how the main function of a Dropwizard application looks like,
public static void main(String[] args) throws Exception {
new ExampleApplication().run(args);
}
such that the main thread exits right after starting the application. This was fine before because the JVM wouldn't exit until all non-daemon threads have exited, which would never happen as there were admin thread pool executor as well as application executor executor each with non-daemon threads in the thread pool. (doc)
Platform threads are designated daemon or non-daemon threads. When the Java virtual machine starts up, there is usually one non-daemon thread (the thread that typically calls the application's main method). The shutdown sequence begins when all started non-daemon threads have terminated. Unstarted non-daemon threads do not prevent the shutdown sequence from beginning.
Starting with JDK21 together with the enablement of virtual threads, this is no longer the case, because virtual thread can not be a non-daemon thread(doc),
Tests if this thread is a daemon thread. The daemon status of a virtual thread is always true.
So what happens right now is that, when virtual thread is enabled for both admin and application connectors, the main thread is the only non-daemon thread(unless you spawn manually either in main or with dependency injection), such that when the main threads exits, the JVM immediately detects the termination of all non-daemon threads, and choose to shutdown, ignoring the virtual thread executor.
The solution I had was that, since the main thread is the only non-daemon thread, I can just make sure it doesn't exist, unless certain things happens like interrupt signal, so I just let the main thread to wait for itself,
public static void main(String[] args) throws Exception {
new ExampleApplication().run(args);
Thread.currentThread().join();
}
Ideally, I would like the run function to return a future or run blocking until completion, like,
public static void main(String[] args) throws Exception {
new ExampleApplication().run(args).wait();
}
PS: Please let me know if there's better way to solve this.
from dropwizard.
Btw, this issue also exists in DW3 as I just ran into a few weeks before, I believe it also exists in DW4, but I haven't had a chance to reproduce on it.
from dropwizard.
Related Issues (20)
- AWS Serverless Example HOT 1
- Dropwizard 4.0.2 + Hibernate + ContainerResponseFilter with NameBinding HOT 3
- Jersey client 2.21 doesnt support Transfer-encoding: chunked, is there any workaround?
- Breaking change in a version between 4.0.1 and 4.0.4 HOT 3
- DropwizardJettyServerAdapter in DropWizard3 causing exception when there are multiple HttpHeaders HOT 9
- Update Logback to fix CVE-2023-6378? HOT 4
- NPE in tests when a factory is used to inject a value to a resource method parameter HOT 2
- Managed virtual thread pool HOT 2
- Deserialization failures due to Afterburner HOT 1
- delay between tests that use DropwizardExtensionsSupport HOT 2
- Logging request and response body with RequestLogFactory HOT 2
- Dependency Injection issue in AuthFilter HOT 4
- Add cache support for stale-while-revalidate HOT 1
- Redirect log output for commands other than "server" HOT 2
- Enhancement: Make Cli ArgumentParsers locale configurable HOT 3
- Enhancement: Expose `message` property in Dropwizard health functionality
- servletEnabled not working when using dropwizard-core:4.0.3 and metrics-jakarta.servlets:4.2.21
- Dropwizard doesn't support HTTP trailers
- Timing-Bug when logging once and a possible workaround
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dropwizard.