vertx-virtual-threads-incubator
                                
                                
                                
                                    vertx-virtual-threads-incubator copied to clipboard
                            
                            
                            
                        netty grpc errors out in ThreadLocal in a virtual thread context
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:
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 -> {
...
Not sure what the solution is here.
Do you have a reproducer?
(Investigating)
have you tried the new Vert.x gRPC implementation ? I believe it should work.
it does but I am blocked by this - https://github.com/eclipse-vertx/vertx-grpc/issues/28