Vaadin Flow & Spring Boot: Error when opened in multiple tabs/windows

698 Views Asked by At

I'm currently developing an application with Vaadin Flow (v11.0.0) and Spring Boot (v2.0.4) using the MVP pattern. The application works fine, as long as it's only open in a single tab. When reloading the whole page is refreshed, which is totally fine. Also opening it in a second tab or window (doesn't matter if incognito or not) works fine. But when I click something in one window and then in the other one the following error occures:

java.lang.IllegalStateException: Cannot access state in VaadinSession or UI without locking the session.
at com.vaadin.flow.server.VaadinSession.checkHasLock(VaadinSession.java:515) ~[flow-server-1.0.5.jar:na]
at com.vaadin.flow.server.VaadinSession.checkHasLock(VaadinSession.java:529) ~[flow-server-1.0.5.jar:na]
at com.vaadin.flow.internal.StateTree.checkHasLock(StateTree.java:390) ~[flow-server-1.0.5.jar:na]
at com.vaadin.flow.internal.StateTree.markAsDirty(StateTree.java:258) ~[flow-server-1.0.5.jar:na]
at com.vaadin.flow.internal.StateNode.markAsDirty(StateNode.java:326) ~[flow-server-1.0.5.jar:na]
at com.vaadin.flow.internal.nodefeature.NodeValue.markAsDirty(NodeValue.java:85) ~[flow-server-1.0.5.jar:na]
at com.vaadin.flow.internal.nodefeature.NodeValue.setValue(NodeValue.java:78) ~[flow-server-1.0.5.jar:na]
at com.vaadin.flow.internal.nodefeature.TextNodeMap.setText(TextNodeMap.java:52) ~[flow-server-1.0.5.jar:na]

I only have a single view (and therefore also presenter) which I annotate like that:

@Route(value = LogAnalysis.route)
@PageTitle(LogAnalysis.name)
class LogAnalysisView(val presenter: LogAnalysis.ViewPresenter) : VerticalLayout(), LogAnalysis.View, BeforeEnterObserver { ... }

@Component
@UIScope
@VaadinSessionScope
class LogAnalysisPresenter(val service: LogAnalysis.Service) : LogAnalysis.ServicePresenter, LogAnalysis.ViewPresenter { ... }
1

There are 1 best solutions below

0
On BEST ANSWER

I managed to solve the issue by adding the @UIScope annotation to the Service (model) as well.

I assumed that the service can be a singleton, as it is only fetching and preparing data from the database, but the service holds a reference to the presenter which gets overwritten every time a new Session is created.