VaadinSession.getSession() is sometimes null in session destroy listeners
See original GitHub issueDescription of the bug / feature
In my usecase I want to keep track of all VaadinSessions. For that reason I am doing the following in the AppShell:
serviceInitEvent.getSource().addSessionInitListener( ... );
serviceInitEvent.getSource().addSessionDestroyListener(sessionDestroyEvent -> {
if(sessionDestroyEvent != null && sessionDestroyEvent.getSession() != null) {
//do smth with the sessionId
//this code is not reached
}
});
Expected behavior
I get the correct session when initialized, and I get the session before it is destroyed.
Actual behavior
The destroyed is session null
.
Problem: I can not track which session was destroyed.
Versions:
- Vaadin / Flow version: 18.0.3
- Java version: 11
- OS version: Windows 10
- Application Server (if applicable): Spring Boot with Tomcat
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Vaadin SessionDestroyListener session access - Stack Overflow
While the session object is available by calling sessionDestroyEvent.getSession() , its state is CLOSING and all attributes have already ...
Read more >com.vaadin.server.VaadinSession.getSession java ... - Tabnine
Returns whether the given session is active or whether it can be closed. * <p> * A session is active if and only...
Read more >VaadinSession (vaadin-all 8.16.1 API)
Retrieves all VaadinSession s which are stored in the given HTTP session. ... returned by addBootstrapListener(BootstrapListener) to remove a listener.
Read more >com.vaadin.server Class VaadinSession - javadoc.io
Locks this session and runs the provided Runnable right away. ... Remove a bootstrap listener that was previously added.
Read more >Vaadin flow: .../vaadin/flow/server/VaadinService.java | Fossies
572 * 573 * @param listener 574 * the vaadin service session destroy listener 575 ... getSession() != null) { 1308 /* 1309...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
In https://github.com/vaadin/flow/issues/6959 it was suggested to use
VaadinRequest.getCurrent().getWrappedSession()
instead ofevent.getSession().getSession()
I couldn’t reproduce the symptoms that you’re describing. I created a new project with everything set as default from https://start.vaadin.com/ and made this addition to the
Application
class:When the application is running, I can see log messages like these:
I also looked at the framework code that creates those event objects and I couldn’t find any code path that wouldn’t have failed with a
NullPointerException
before an event without a session would have reached the listener.Based on that, I have two potential things for you to look up:
if
? You can find out that by adding the same kind of simple logging that I had in my test code.new Exception().printStackTrace();
.