You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently a JVM shutdown hook is added when DefaultClientFactory is used for the first time (code). It is possible that a JVM shutdown hook is being added after the JVM has started its shutdown and results in an exception below:
Caused by: java.lang.IllegalStateException: Shutdown in progress
at java.base/java.lang.ApplicationShutdownHooks.add(ApplicationShutdownHooks.java:66)
at java.base/java.lang.Runtime.addShutdownHook(Runtime.java:216)
at grpc_shaded.com.linecorp.armeria.client.DefaultClientFactory.<clinit>(DefaultClientFactory.java:79)
... 24 more
More specifically, one situation can be that a client (e.g. Armeria gRPC client) was created for the first time leads to DefaultClientFactory being used for the first time. The JVM is already in shutdown when that happens.
A simple improvement could be:
static {
if (DefaultClientFactory.class.getClassLoader() == ClassLoader.getSystemClassLoader()) {
if (!shutdownHookDisabled) { // Skip adding the hook if we explicitly disabled it.Runtime.getRuntime().addShutdownHook(newThread(() -> {
ClientFactory.closeDefault();
}));
}
}
}
and/or try-catch the java.lang.IllegalStateException: Shutdown in progress exception around Runtime.getRuntime().addShutdownHook and log something like "Trying to add shutdown hook during JVM shutdown, skip it because it does not matter any more since the JVM is already shutting down :)".
The text was updated successfully, but these errors were encountered:
Motivation:
Currently a JVM shutdown hook is added when DefaultClientFactory is used
for the first time
([code](https://github.com/line/armeria/blob/main/core/src/main/java/com/linecorp/armeria/client/DefaultClientFactory.java#L80-L83)).
It is possible that a JVM shutdown hook is being added after the JVM has
started its shutdown and results in an exception below:
```
Caused by: java.lang.IllegalStateException: Shutdown in progress
at java.base/java.lang.ApplicationShutdownHooks.add(ApplicationShutdownHooks.java:66)
at java.base/java.lang.Runtime.addShutdownHook(Runtime.java:216)
at grpc_shaded.com.linecorp.armeria.client.DefaultClientFactory.<clinit>(DefaultClientFactory.java:79)
... 24 more
```
Modifications:
- Skip adding the hook if we explicitly disabled it.
- Add try-catch for ` java.lang.IllegalStateException`
Result:
- Closes#5494
---------
Co-authored-by: jrhee17 <guins_j@guins.org>
Discussion context.
Currently a JVM shutdown hook is added when
DefaultClientFactory
is used for the first time (code). It is possible that a JVM shutdown hook is being added after the JVM has started its shutdown and results in an exception below:More specifically, one situation can be that a client (e.g. Armeria gRPC client) was created for the first time leads to
DefaultClientFactory
being used for the first time. The JVM is already in shutdown when that happens.A simple improvement could be:
and/or try-catch the java.lang.IllegalStateException: Shutdown in progress exception around
Runtime.getRuntime().addShutdownHook
and log something like "Trying to add shutdown hook during JVM shutdown, skip it because it does not matter any more since the JVM is already shutting down :)".The text was updated successfully, but these errors were encountered: