Quarkus: Problem with native build: Vertx SockJS

Created on 12 Nov 2019  路  3Comments  路  Source: quarkusio/quarkus

I got a problem when building my quarkus microservice using Vertx SockJS when I want to add the mothod sockJSHandler.bridge :

This is my java class :

@ApplicationScoped
public class MessagingConfig {

    private static final String ACCESS_TOKEN = "access-token";

    private final IdentityProviderManager identityProviderManager;
    private final MessageHandler messageHandler;
    private final Vertx vertx;

    @Inject
    public MessagingConfig(IdentityProviderManager identityProviderManager, MessageHandler messageHandler, Vertx vertx) {
        this.identityProviderManager = identityProviderManager;
        this.messageHandler = messageHandler;
        this.vertx = vertx;
    }

    public void init(@Observes Router router) {

        router.route("/ws/chat/*").handler(routingContext -> {
            String token = routingContext.request().getParam(ACCESS_TOKEN);
            if(token == null || token.isEmpty()) {
                routingContext.response().setStatusCode(401).end();
                return;
            }
            identityProviderManager.authenticate(new TokenAuthenticationRequest(new AccessTokenCredential(token)))
                .thenAccept((securityIdentity) -> {
                    routingContext.setUser(new QuarkusHttpUser(securityIdentity));
                    routingContext.next();
                })
                .exceptionally(e -> {
                    Future.failedFuture(new HttpStatusException(401));
                    return null;
                });
        });
        router.route("/ws/chat/*").handler(eventBusHandler());
        router.route().handler(StaticHandler.create().setCachingEnabled(false));
    }

    private SockJSHandler eventBusHandler() {
        BridgeOptions options = new BridgeOptions()
                .addOutboundPermitted(new PermittedOptions().setAddressRegex("out"))
                .addInboundPermitted(new PermittedOptions().setAddressRegex("in"));

        EventBus eventBus = vertx.eventBus();
        SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
        sockJSHandler.bridge(options, event -> {
            if (event.type() == BridgeEventType.SOCKET_CREATED) {
                messageHandler.onOpen(event,eventBus);
            }

            if (event.type() == BridgeEventType.SEND) {
                messageHandler.onMessage(event,eventBus);
            }

            if (event.type() == BridgeEventType.SOCKET_CLOSED) {
                messageHandler.onClose(event,eventBus);
            }

            event.complete(true);
        });
        return sockJSHandler;
    }
}

and I got an error just when I add this piece of code of SockJSHandler.bridge :

sockJSHandler.bridge(options, event -> {
            if (event.type() == BridgeEventType.SOCKET_CREATED) {
                messageHandler.onOpen(event,eventBus);
            }

            if (event.type() == BridgeEventType.SEND) {
                messageHandler.onMessage(event,eventBus);
            }

            if (event.type() == BridgeEventType.SOCKET_CLOSED) {
                messageHandler.onClose(event,eventBus);
            }

            event.complete(true);
        });

I got this error :

Error: No instances of io.netty.buffer.UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use -H:+TraceClassInitialization.
Detailed message:
Trace:  object io.netty.buffer.UnreleasableByteBuf
        object io.vertx.core.buffer.impl.BufferImpl
        method io.vertx.ext.web.handler.sockjs.impl.XhrTransport.access$100()
Call path from entry point to io.vertx.ext.web.handler.sockjs.impl.XhrTransport.access$100(): 
        at io.vertx.ext.web.handler.sockjs.impl.XhrTransport.access$100(XhrTransport.java:56)
        at io.vertx.ext.web.handler.sockjs.impl.XhrTransport$XhrStreamingListener.sendFrame(XhrTransport.java:225)
        at io.vertx.ext.web.handler.sockjs.impl.SockJSSession.lambda$new$0(SockJSSession.java:119)
        at io.vertx.ext.web.handler.sockjs.impl.SockJSSession$$Lambda$1315/1256080735.handle(Unknown Source)
        at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:369)
        at io.vertx.core.impl.WorkerContext.lambda$wrapTask$0(WorkerContext.java:35)
        at io.vertx.core.impl.WorkerContext$$Lambda$799/1899710327.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:460)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)

com.oracle.svm.core.util.UserError$UserException: No instances of io.netty.buffer.UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use -H:+TraceClassInitialization.
Detailed message:
Trace:  object io.netty.buffer.UnreleasableByteBuf
        object io.vertx.core.buffer.impl.BufferImpl
        method io.vertx.ext.web.handler.sockjs.impl.XhrTransport.access$100()
Call path from entry point to io.vertx.ext.web.handler.sockjs.impl.XhrTransport.access$100(): 
        at io.vertx.ext.web.handler.sockjs.impl.XhrTransport.access$100(XhrTransport.java:56)
        at io.vertx.ext.web.handler.sockjs.impl.XhrTransport$XhrStreamingListener.sendFrame(XhrTransport.java:225)
        at io.vertx.ext.web.handler.sockjs.impl.SockJSSession.lambda$new$0(SockJSSession.java:119)
        at io.vertx.ext.web.handler.sockjs.impl.SockJSSession$$Lambda$1315/1256080735.handle(Unknown Source)
        at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:369)
        at io.vertx.core.impl.WorkerContext.lambda$wrapTask$0(WorkerContext.java:35)
        at io.vertx.core.impl.WorkerContext$$Lambda$799/1899710327.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:460)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)

        at com.oracle.svm.core.util.UserError.abort(UserError.java:75)
        at com.oracle.svm.hosted.FallbackFeature.reportAsFallback(FallbackFeature.java:223)
        at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:737)
        at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:526)
        at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:444)
        at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
        at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
        at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
        at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
        at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of io.netty.buffer.UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use -H:+TraceClassInitialization.
Detailed message:
Trace:  object io.netty.buffer.UnreleasableByteBuf
        object io.vertx.core.buffer.impl.BufferImpl
        method io.vertx.ext.web.handler.sockjs.impl.XhrTransport.access$100()
Call path from entry point to io.vertx.ext.web.handler.sockjs.impl.XhrTransport.access$100(): 
        at io.vertx.ext.web.handler.sockjs.impl.XhrTransport.access$100(XhrTransport.java:56)
        at io.vertx.ext.web.handler.sockjs.impl.XhrTransport$XhrStreamingListener.sendFrame(XhrTransport.java:225)
        at io.vertx.ext.web.handler.sockjs.impl.SockJSSession.lambda$new$0(SockJSSession.java:119)
        at io.vertx.ext.web.handler.sockjs.impl.SockJSSession$$Lambda$1315/1256080735.handle(Unknown Source)
        at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:369)
        at io.vertx.core.impl.WorkerContext.lambda$wrapTask$0(WorkerContext.java:35)
        at io.vertx.core.impl.WorkerContext$$Lambda$799/1899710327.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:460)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)

        at com.oracle.graal.pointsto.constraints.UnsupportedFeatures.report(UnsupportedFeatures.java:130)
        at com.oracle.graal.pointsto.BigBang.finish(BigBang.java:565)
        at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:688)
        ... 7 more
Error: Image build request failed with exit status 1

How can I deal with this error please

kinquestion

All 3 comments

The XhrTransport class must be declared as runtime only.

Try to add --initialize-at-run-time=io.vertx.ext.web.handler.sockjs.impl.XhrTransport to the additional argument of the native build.

Thanks!

Was this page helpful?
0 / 5 - 0 ratings