vaadin / quarkus

An extension to Quarkus to support Vaadin Flow
Apache License 2.0
28 stars 3 forks source link

Vaadin Quarkus push enabled application runs into Vertx Thread blocked during findVaadinSession #144

Closed Koekebakkert closed 2 weeks ago

Koekebakkert commented 6 months ago

Description of the bug

All my Vaadin Quarkus push enabled applications run into Vertx Thread blocked exceptions during findVaadinSession quite often (but not always). The actual vaadin browser session will hang during the block. The behavior occurs in both dev mode and production mode.

The stack traces look like this on startup but the same exception also occur later when a new session is created:

2023-12-21 10:12:28,763 INFO  [io.quarkus] (main) Profile prod activated.                                                                                                                                    
2023-12-21 10:12:28,763 INFO  [io.quarkus] (main) Installed features: [cdi, logging-manager, micrometer, rest-client-reactive, rest-client-reactive-jackson, servlet, smallrye-context-propagation, smallrye-health, vaadin-quarkus, vertx, websockets, websockets-client]                                                                                                                                                
2023-12-21 14:35:43,051 INFO  [com.vaa.qua.QuarkusInstantiator] (executor-thread-1) Can't find any @VaadinServiceScoped bean implementing 'I18NProvider'. Cannot use CDI beans for I18N, falling back to the default behavior.                                                                                                                                                                                            
2023-12-21 14:35:43,370 INFO  [io.qua.htt.access-log] (executor-thread-1) "GET / HTTP/1.1" 200                                                                                                               
2023-12-21 14:35:43,853 INFO  [io.qua.htt.access-log] (executor-thread-3) "GET /icons/favico.ico HTTP/1.1" 200                                                                                               
2023-12-21 14:35:47,401 WARN  [io.ver.cor.imp.BlockedThreadChecker] (vertx-blocked-thread-checker) Thread Thread[vert.x-eventloop-thread-0,5,main] has been blocked for 2916 ms, time limit is 2000 ms: io.vertx.core.VertxException: Thread blocked                                                                                                                                                                      
        at java.base@17.0.9/jdk.internal.misc.Unsafe.park(Native Method)                                                                                                                                     
        at java.base@17.0.9/java.util.concurrent.locks.LockSupport.park(LockSupport.java:211)                                                                                                                
        at java.base@17.0.9/java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:715)                                                                               
        at java.base@17.0.9/java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:938)                                                                               
        at java.base@17.0.9/java.util.concurrent.locks.ReentrantLock$Sync.lock(ReentrantLock.java:153)                                                                                                       
        at java.base@17.0.9/java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:322)                                                                                                            
        at com.vaadin.flow.server.VaadinService.lockSession(VaadinService.java:790)                                                                                                                          
        at com.vaadin.flow.server.VaadinService.findOrCreateVaadinSession(VaadinService.java:837)                                                                                                            
        at com.vaadin.flow.server.VaadinService.findVaadinSession(VaadinService.java:682)                                                                                                                    
        at com.vaadin.flow.server.communication.PushHandler.callWithUi(PushHandler.java:256)                                                                                                                 
        at com.vaadin.flow.server.communication.PushHandler.onConnect(PushHandler.java:602)                                                                                                                  
        at com.vaadin.flow.server.communication.PushAtmosphereHandler.onConnect(PushAtmosphereHandler.java:103)                                                                                              
        at com.vaadin.flow.server.communication.PushAtmosphereHandler.onRequest(PushAtmosphereHandler.java:77)                                                                                               
        at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:217)                                                                                                                   
        at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:103)                                                                                                                
        at org.atmosphere.container.Servlet30CometSupport.service(Servlet30CometSupport.java:67)                                                                                                             
        at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:2284)                                                                                                              
        at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:574)                                                                                                   
        at org.atmosphere.websocket.DefaultWebSocketProcessor.open(DefaultWebSocketProcessor.java:213)                                                                                                       
        at org.atmosphere.container.JSR356Endpoint.onOpen(JSR356Endpoint.java:254)                                                                                                                           
        at io.undertow.websockets.EndpointSessionHandler.connected(EndpointSessionHandler.java:119)                                                                                                          
        at io.undertow.websockets.vertx.VertxWebSocketHandler$1.accept(VertxWebSocketHandler.java:120)                                                                                                       
        at io.undertow.websockets.vertx.VertxWebSocketHandler$1.accept(VertxWebSocketHandler.java:117)                                                                                                       
        at io.undertow.websockets.handshake.Handshake$1.accept(Handshake.java:147)                                                                                                                           
        at io.undertow.websockets.vertx.VertxWebSocketHttpExchange$1.handle(VertxWebSocketHttpExchange.java:129)                                                                                             
        at io.undertow.websockets.vertx.VertxWebSocketHttpExchange$1.handle(VertxWebSocketHttpExchange.java:121)                                                                                             
        at io.vertx.core.impl.future.FutureImpl$3.onSuccess(FutureImpl.java:141)                                                                                                                             
        at io.vertx.core.impl.future.FutureBase.lambda$emitSuccess$0(FutureBase.java:54)                                                                                                                     
        at io.vertx.core.impl.future.FutureBase$$Lambda$553/0x00007f4f0840b000.run(Unknown Source)                                                                                                           
        at io.vertx.core.impl.EventLoopContext.execute(EventLoopContext.java:86)                                                                                                                             
        at io.vertx.core.impl.DuplicatedContext.execute(DuplicatedContext.java:184)                                                                                                                          
        at io.vertx.core.impl.future.FutureBase.emitSuccess(FutureBase.java:51)                                                                                                                              
        at io.vertx.core.impl.future.FutureImpl.tryComplete(FutureImpl.java:211)                                                                                                                             
        at io.vertx.core.impl.future.PromiseImpl.tryComplete(PromiseImpl.java:23)                                                                                                                            
        at io.vertx.core.Promise.complete(Promise.java:66)                                                                                                                                                   
         at io.vertx.core.impl.future.PromiseImpl.operationComplete(PromiseImpl.java:65)
        at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:590)
        at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:583)
        at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:559)
        at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:492)
        at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:636)
        at io.netty.util.concurrent.DefaultPromise.setSuccess0(DefaultPromise.java:625)
        at io.netty.util.concurrent.DefaultPromise.trySuccess(DefaultPromise.java:105)
        at io.netty.util.internal.PromiseNotificationUtil.trySuccess(PromiseNotificationUtil.java:48)
        at io.netty.channel.ChannelOutboundBuffer.safeSuccess(ChannelOutboundBuffer.java:726)
        at io.netty.channel.ChannelOutboundBuffer.remove(ChannelOutboundBuffer.java:281)
        at io.netty.channel.ChannelOutboundBuffer.removeBytes(ChannelOutboundBuffer.java:361)
        at io.netty.channel.socket.nio.NioSocketChannel.doWrite(NioSocketChannel.java:421)
        at io.netty.channel.AbstractChannel$AbstractUnsafe.flush0(AbstractChannel.java:931)
        at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.flush0(AbstractNioChannel.java:354)
        at io.netty.channel.AbstractChannel$AbstractUnsafe.flush(AbstractChannel.java:895)
        at io.netty.channel.DefaultChannelPipeline$HeadContext.flush(DefaultChannelPipeline.java:1372)
        at io.netty.channel.AbstractChannelHandlerContext.invokeFlush0(AbstractChannelHandlerContext.java:921)
        at io.netty.channel.AbstractChannelHandlerContext.invokeFlush(AbstractChannelHandlerContext.java:907)
        at io.netty.channel.AbstractChannelHandlerContext.flush(AbstractChannelHandlerContext.java:893)
        at io.netty.handler.stream.ChunkedWriteHandler.doFlush(ChunkedWriteHandler.java:313)
        at io.netty.handler.stream.ChunkedWriteHandler.flush(ChunkedWriteHandler.java:131)
        at io.netty.channel.AbstractChannelHandlerContext.invokeFlush0(AbstractChannelHandlerContext.java:923)
        at io.netty.channel.AbstractChannelHandlerContext.invokeFlush(AbstractChannelHandlerContext.java:907)
        at io.netty.channel.AbstractChannelHandlerContext.flush(AbstractChannelHandlerContext.java:893)
        at io.vertx.core.net.impl.ConnectionBase.endReadAndFlush(ConnectionBase.java:146)
        at io.vertx.core.net.impl.VertxHandler.channelReadComplete(VertxHandler.java:148)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(AbstractChannelHandlerContext.java:484)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(AbstractChannelHandlerContext.java:463)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelReadComplete(AbstractChannelHandlerContext.java:456)
        at io.netty.handler.timeout.IdleStateHandler.channelReadComplete(IdleStateHandler.java:295)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(AbstractChannelHandlerContext.java:484)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(AbstractChannelHandlerContext.java:463)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelReadComplete(AbstractChannelHandlerContext.java:456)
        at io.netty.handler.codec.ByteToMessageDecoder.channelReadComplete(ByteToMessageDecoder.java:358)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(AbstractChannelHandlerContext.java:486)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(AbstractChannelHandlerContext.java:463)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelReadComplete(AbstractChannelHandlerContext.java:456)
        at io.netty.channel.DefaultChannelPipeline$HeadContext.channelReadComplete(DefaultChannelPipeline.java:1415)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(AbstractChannelHandlerContext.java:482)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(AbstractChannelHandlerContext.java:463)
        at io.netty.channel.DefaultChannelPipeline.fireChannelReadComplete(DefaultChannelPipeline.java:925)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:171)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)                                                                                                                       
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)                                                                                                             
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)                                                                                                                      
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)                                                                                                                                      
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)                                                                                                      
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)                                                                                                                         
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)                                                                                                             
        at java.base@17.0.9/java.lang.Thread.run(Thread.java:840)                                                                                                                                            

Expected behavior

No blocking exception occurs and the browser session runs smoothly.

Minimal reproducible example

Download the sample application from:

https://github.com/vaadin/base-starter-flow-quarkus.git

Add @Push to the class com.example.starter.base.AppConfig.

Run the application, e.g.

quarkus dev

or

mvn quarkus:dev

With a supported webbrowser goto http://localhost:8080

If the exceptions do not occur immediately, just refresh the page a couple of times.

Also the following exception will occur:

2023-12-21 16:41:12,630 ERROR [com.vaa.flo.ser.com.PushAtmosphereHandler] (Atmosphere-Shared-12) Exception in push connection: java.io.IOException: Connection remotely closed for 01a0f79f-3319-44c7-a3b9-21f12408331f                                                                                         
        at org.atmosphere.websocket.WebSocket.write(WebSocket.java:237)                                                                                 
        at org.atmosphere.websocket.WebSocket.write(WebSocket.java:227)                                                                                 
        at org.atmosphere.websocket.WebSocket.write(WebSocket.java:48)
        at org.atmosphere.cpr.AtmosphereResponseImpl$Stream.write(AtmosphereResponseImpl.java:955)
        at org.atmosphere.handler.AbstractReflectorAtmosphereHandler.onStateChange(AbstractReflectorAtmosphereHandler.java:154)
        at com.vaadin.flow.server.communication.PushAtmosphereHandler.onStateChange(PushAtmosphereHandler.java:54)
        at org.atmosphere.cpr.DefaultBroadcaster.invokeOnStateChange(DefaultBroadcaster.java:1036)
        at org.atmosphere.cpr.DefaultBroadcaster.prepareInvokeOnStateChange(DefaultBroadcaster.java:1056)
        at org.atmosphere.cpr.DefaultBroadcaster.executeAsyncWrite(DefaultBroadcaster.java:870)
        at org.atmosphere.cpr.DefaultBroadcaster$2.run(DefaultBroadcaster.java:477)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:840)

Versions

mcollovati commented 6 months ago

Probably a duplicate of vaadin/quarkus#138

Koekebakkert commented 6 months ago

Although the exception looks the same the situation is quite different. There is no UnsupportedOperationException and I cannot summon the exception without using the @Push annotation on the starter code.

manuelmuggliinacta commented 6 months ago

Although the exception looks the same the situation is quite different. There is no UnsupportedOperationException and I cannot summon the exception without using the @Push annotation on the starter code.

I'm experiencing the same issue. It seems to happen if there is an exception while executing the push. this request then seems not to be terminated correctly

mcollovati commented 6 months ago

The workaround in this comment seems to work for me on the starter project.

Koekebakkert commented 6 months ago

Thanks Marco! I can confirm that it also solves the thread blocked exception in the findVaadinSession case of this issue in dev mode for all my quarkus vaadin applications.

mcollovati commented 2 weeks ago

Closing as potential duplicate of #138