Suppose I create a netty grpc server on a virtual thread context. Observe the following error when the server is stopped:
java.lang.NullPointerException: Cannot invoke "java.util.List.remove(Object)" because the return value of "java.lang.ThreadLocal.get()" is null
at io.vertx.grpc.VertxServer$ActualServer.lambda$stop$7(VertxServer.java:136)
at io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:264)
at io.vertx.await.impl.VirtualThreadContext.lambda$run$1(VirtualThreadContext.java:102)
at java.base/java.lang.VirtualThread.run(VirtualThread.java:305)
at java.base/java.lang.VirtualThread$VThreadContinuation.lambda$new$0(VirtualThread.java:177)
at java.base/jdk.internal.vm.Continuation.enter0(Continuation.java:327)
at java.base/jdk.internal.vm.Continuation.enter(Continuation.java:320)
For context:
public class VertxServer extends Server {
private static final ConcurrentMap<ServerID, ActualServer> map = new ConcurrentHashMap<>();
private static class ActualServer {
...
final ThreadLocal<List<ContextInternal>> contextLocal = new ThreadLocal<>();
...
void stop(ContextInternal context, Promise<Void> promise) {
boolean shutdown = count.decrementAndGet() == 0;
context.runOnContext(v -> {
group.removeWorker(context.nettyEventLoop());
// ERROR LINE
contextLocal.get().remove(context);
if (shutdown) {
map.remove(id);
context.executeBlocking(p -> {
...
Version
4.4.2 (latest)
Context
Suppose I create a netty grpc server on a virtual thread context. Observe the following error when the server is stopped:
For context:
Not sure what the solution is here.
Do you have a reproducer?
(Investigating)