Vaadin does not keep Vaadin Session for a user

Hello,
In my Vaadin application during GhostInspector e2e test I encountered weird fatal error.
Very often in several different parts of application Window i unexpectedly closed.
From stacktrace I can only tell that getCurrent().getUserName() returns null so it seems that Vaadin session is not kept.
Here is my example stack trace:

[code]
[code]
[code]
[code]
20170707 07:27:01.285 [pool-8-thread-7]
 ERROR xxx.xxx.ui.ErrorHandler - Unexcepted fatal internal error: {}
java.util.concurrent.ExecutionException: java.lang.NullPointerException
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:192)
    at com.vaadin.server.VaadinSession$FutureAccess.get(VaadinSession.java:124)
    at com.vaadin.server.VaadinService.runPendingAccessTasks(VaadinService.java:1863)
    at com.vaadin.server.VaadinSession.unlock(VaadinSession.java:992)
    at com.vaadin.server.VaadinService.ensureAccessQueuePurged(VaadinService.java:1823)
    at com.vaadin.server.VaadinService.accessSession(VaadinService.java:1789)
    at com.vaadin.server.VaadinSession.access(VaadinSession.java:1392)
    at com.vaadin.ui.UI.access(UI.java:1455)
    at common.CommonAction.accessUi(CommonAction.java:67)
    at fxxx.list.XXXListWindow.receiveBroadcast(XXXWindow.java:86)
    at xxx.push.PushBroadcaster.lambda$null$3(PushBroadcaster.java:33)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException: null
    at xxx.service.runner.postalcode.XXXService.count(XXXService.java:48)
    at xxx.service.runner.postalcode.XXXQuery.size(XXXQuery.java:50)
    at org.vaadin.addons.lazyquerycontainer.LazyQueryView.getQuery(LazyQueryView.java:402)
    at org.vaadin.addons.lazyquerycontainer.LazyQueryView.getQuerySize(LazyQueryView.java:387)
    at org.vaadin.addons.lazyquerycontainer.LazyQueryView.size(LazyQueryView.java:214)
    at org.vaadin.addons.lazyquerycontainer.LazyQueryContainer.size(LazyQueryContainer.java:181)
    at xxx.common.window.AbstractLazyLoadingGridWindow.lambda$createRowsSumFooter$9d1bb149$1(AbstractLazyLoadingGridWindow.java:77)
    at org.vaadin.addons.lazyquerycontainer.LazyQueryContainer.notifyItemSetChanged(LazyQueryContainer.java:445)
    at org.vaadin.addons.lazyquerycontainer.LazyQueryContainer.refresh(LazyQueryContainer.java:436)
    at xxxi.common.window.AbstractLazyLoadingGridWindow.loadData(AbstractLazyLoadingGridWindow.java:86)
    at com.vaadin.ui.UI.accessSynchronously(UI.java:1392)
    at com.vaadin.ui.UI$4.run(UI.java:1458)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at com.vaadin.server.VaadinService.runPendingAccessTasks(VaadinService.java:1860)
    ... 11 common frames omitted
20170707 07:27:01.286 [pool-8-thread-7]
 ERROR xxx.xxx.ErrorHandler - Unexcepted fatal internal error: {}
java.util.concurrent.ExecutionException: java.lang.NullPointerException
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:192)
    at com.vaadin.server.VaadinSession$FutureAccess.get(VaadinSession.java:124)
    at com.vaadin.server.VaadinService.runPendingAccessTasks(VaadinService.java:1863)
    at com.vaadin.server.VaadinSession.unlock(VaadinSession.java:992)
    at com.vaadin.server.VaadinService.ensureAccessQueuePurged(VaadinService.java:1823)
    at com.vaadin.server.VaadinService.accessSession(VaadinService.java:1789)
    at com.vaadin.server.VaadinSession.access(VaadinSession.java:1392)
    at com.vaadin.ui.UI.access(UI.java:1455)
    at xxx.common.CommonAction.accessUi(CommonAction.java:67)
    at xxx.list.XXXListWindow.receiveBroadcast(XXXListWindow.java:86)
    at xxx.PushBroadcaster.lambda$null$3(PushBroadcaster.java:33)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException: null
    at xxx.service.runner.postalcode.XXXService.count(XXXService.java:48)
    at xxx.service.runner.postalcode.XXXQuery.size(XXXQuery.java:50)
    at org.vaadin.addons.lazyquerycontainer.LazyQueryView.getQuery(LazyQueryView.java:402)
    at org.vaadin.addons.lazyquerycontainer.LazyQueryView.getQuerySize(LazyQueryView.java:387)
    at org.vaadin.addons.lazyquerycontainer.LazyQueryView.size(LazyQueryView.java:214)
    at org.vaadin.addons.lazyquerycontainer.LazyQueryContainer.size(LazyQueryContainer.java:181)
    at xxx.ui.common.window.AbstractLazyLoadingGridWindow.lambda$createRowsSumFooter$9d1bb149$1(AbstractLazyLoadingGridWindow.java:77)
    at org.vaadin.addons.lazyquerycontainer.LazyQueryContainer.notifyItemSetChanged(LazyQueryContainer.java:445)
    at org.vaadin.addons.lazyquerycontainer.LazyQueryContainer.refresh(LazyQueryContainer.java:436)
    at xxx.common.window.AbstractLazyLoadingGridWindow.loadData(AbstractLazyLoadingGridWindow.java:86)
    at com.vaadin.ui.UI.accessSynchronously(UI.java:1392)
    at com.vaadin.ui.UI$4.run(UI.java:1458)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at com.vaadin.server.VaadinService.runPendingAccessTasks(VaadinService.java:1860)
    ... 11 common frames omitted
[/code]
[/code]
[/code]
[/code]

Have you ever had such error? What can be cause of that?

I had a similar problem with vaadin unit testing:

Sometimes my current UI was suddenly null. The solution was to create a variable which contained the mocked UI, because vaadin stores the current UI as a WeakReference. If the variable doesn’t exist, the garbage collector cleans up all the WeakReferences after some time.

Maybe this helps.