Connection Lost error in Java Spring Boot App

I am beginner. I added vaadin-spring-boot-starter version 24.6.0 in my pom.xml file and wrote a java class that extends VerticalLayout. It adds a grid. It has a @Route annotation

When I start my application locally, it runs in development mode and fails with a message “Connection Lost” in the chrome browser tab.
I tried enabling production mode by adding vaadin.productionMode=true in application.properties file and running the build (with few more steps) but the outcome is the same.

  1. Kindly suggest a fix for the “Connection Lost” error
  2. I understand that vaadin uses websockets internally. How I configure to it use long polling and would there be any visible side effects apart from performance?

Thanks.

  1. That version sounds really old
  2. I think you have spring security in place without rules for Vaadin? Did you start with a project from start.vaadin.com?
  3. Did you read the documentation about push? Websocket only used for Push - not for the normal communication
  1. Sorry it was a minor typo. It is 24.6.0. I have corrected the original post.
  2. No I have an existing java spring boot application where I want to integrate vaadin. I haven’t started the project with start.vaadin.com
  3. That’s great. So websockets would be used only when I add @Push annotation somewhere in my code.

Any suggestions on what could be the root cause of the “Connection Lost” error?

I think you have spring security in place without rules for Vaadin.

Compare your setup with a sample project from start.vaadin.com would be the saftest bet, otherwise it’s impossible to help without knowing you full setup

1 Like

I tried comparing the sample project with mine and matching it but can’t figure out what could be causing the connection lost error. Nothing is displayed when navigating to the page mentioned in the @Route annotation.

I also checked through mvn dependency:tree -Dincludes=org.springframework.security command to see if our application had spring security dependencies and it turned out that spring security jars are getting added through the vaadin spring boot starter jar only. The output of the command is

[INFO] \- com.vaadin:vaadin-spring-boot-starter:jar:24.6.0:compile
[INFO]    \- com.vaadin:hilla:jar:24.6.0:compile
[INFO]       \- com.vaadin:hilla-endpoint:jar:24.6.0:compile
[INFO]          \- org.springframework.security:spring-security-core:jar:6.1.9:compile
[INFO]             \- org.springframework.security:spring-security-crypto:jar:6.1.9:compile

Adding a screenshot of the issue for reference

Let me know if you have some inputs on how to troubleshoot this further.

When I enable com.vaadin debug logs I see the below error. I wonder why push is attempted when I don’t have any @Push annotation in my source code. Also the stack trace indicates that websockets are used.

Any expert inputs?

[http-nio-8080-exec-5] DEBUG c.v.f.s.communication.PushHandler - Session expired before push disconnect event was received
com.vaadin.flow.server.SessionExpiredException: null
	at com.vaadin.flow.server.VaadinService.doFindOrCreateVaadinSession(VaadinService.java:985)
	at com.vaadin.flow.server.VaadinService.findOrCreateVaadinSession(VaadinService.java:921)
	at com.vaadin.flow.server.VaadinService.findVaadinSession(VaadinService.java:760)
	at com.vaadin.flow.server.communication.PushHandler.handleConnectionLost(PushHandler.java:434)
	at com.vaadin.flow.server.communication.PushHandler.connectionLost(PushHandler.java:388)
	at com.vaadin.flow.server.communication.PushAtmosphereHandler.onStateChange(PushAtmosphereHandler.java:62)
	at org.atmosphere.cpr.AsynchronousProcessor.invokeAtmosphereHandler(AsynchronousProcessor.java:538)
	at org.atmosphere.cpr.AsynchronousProcessor.completeLifecycle(AsynchronousProcessor.java:480)
	at org.atmosphere.cpr.AsynchronousProcessor.endRequest(AsynchronousProcessor.java:584)
	at org.atmosphere.websocket.DefaultWebSocketProcessor.executeClose(DefaultWebSocketProcessor.java:689)
	at org.atmosphere.websocket.DefaultWebSocketProcessor.close(DefaultWebSocketProcessor.java:635)
	at org.atmosphere.container.JSR356Endpoint.onClose(JSR356Endpoint.java:318)
	at org.apache.tomcat.websocket.WsSession.fireEndpointOnClose(WsSession.java:730)
	at org.apache.tomcat.websocket.WsSession.onClose(WsSession.java:638)
	at org.apache.tomcat.websocket.WsFrameBase.processDataControl(WsFrameBase.java:347)
	at org.apache.tomcat.websocket.WsFrameBase.processData(WsFrameBase.java:279)
	at org.apache.tomcat.websocket.WsFrameBase.processInputBuffer(WsFrameBase.java:130)
	at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:85)
	at org.apache.tomcat.websocket.server.WsFrameServer.doOnDataAvailable(WsFrameServer.java:184)
	at org.apache.tomcat.websocket.server.WsFrameServer.notifyDataAvailable(WsFrameServer.java:164)
	at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler.upgradeDispatch(WsHttpUpgradeHandler.java:152)
	at org.apache.coyote.http11.upgrade.UpgradeProcessorInternal.dispatch(UpgradeProcessorInternal.java:60)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:57)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:904)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1741)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1190)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
	at java.base/java.lang.Thread.run(Thread.java:833)

On troubleshooting further I could see the issue getting resolved if I add the vaadin.url-mapping property in my application.properties file.

The UI is now showing up.

Could someone explain how is this linked with the “Connection Lost” error I see in the browser and the websocket error stacktrace in the debug logs? @knoobie ?

Thanks