Repository navigation
Description
Description
A RequestEndedEvent listener, new in 25.4, that writes a SharedValueSignal runs every element effect of the request's own UI on the request thread, without the session lock, and the effect fails:
event.getSource().getEventBus().addListener(RequestEndedEvent.class,
ended -> ENDED.update(count -> count + 1));
// in a view
Signal.effect(count, () -> count.setText("requests ended: " + ENDED.get()));Exception in thread "http-nio-8125-exec-1" java.lang.IllegalStateException: Cannot access state in VaadinSession or UI without locking the session.
at com.vaadin.flow.server.VaadinSession.checkHasLock(VaadinSession.java:683)
at com.vaadin.flow.dom.ElementEffect.lambda$enableEffect$ff2b8a2a$1(ElementEffect.java:272)
The effect's own action throws, and then the error handler throws again on getErrorHandler(). ElementEffect.enableEffect decides with UI.getCurrent() == ui alone:
if (UI.getCurrent() == ui) {
// Run immediately if on the same UI
command.run();
} else { ... ui.access ... }When the request ends, the lock is already released but UI.getCurrent() still names the request's UI, so the effect takes the inline branch. Effects of other UIs go through the dispatcher and work.
Why it matters
A request end listener is where request counters and timings belong, and the shared signal is how they reach a live view. The view that shows them is exactly the one whose own requests trigger the failure: the number stops moving after the first click, and the log fills with an exception per request. In the application where it was found, the lost update also took the response of the click with it, so a button on the same page did nothing.
Expected
The inline branch checks that the current thread holds the session lock, ui.getSession().hasLock(), and otherwise the effect is dispatched through ui.access like any other thread's.
Workaround
The listener clears the current instances around the signal write, so the effect sees no current UI and is dispatched:
var current = CurrentInstance.getInstances();
CurrentInstance.clearAll();
try {
ENDED.update(count -> count + 1);
} finally {
CurrentInstance.restoreInstances(current);
}Reproduce
mvn spring-boot:run, and open http://localhost:8125/.- The page shows how many requests have ended, 3 on a fresh start. Press Click.
- The number does not move however many times Click is pressed, and the log shows the exception above for the requests of this page.
With the workaround in RequestCounter, the number moves with every click, 34 to 36 after two, and the log stays clean.
RequestEndedEvent is new in 25.4, so the project does not compile on 25.3.5.
Found on 25.4.0-beta2.
Getting the project
25-effect-unlocked-request-end.zip, 4 KB, sources only. Unzip it and:
mvn spring-boot:run
Activity
totally-not-ai commentedon Nov 23, 2026
Triage: confirmed bug. A signal effect of the request's own UI throws a session-lock exception when a shared signal is changed after the request has released the lock, and the UI update is lost.
RequestEndedEventlistener (25.4) or aVaadinRequestInterceptor.requestEnd. Effects of other UIs are fine.mainand 25.0–25.4. Before 25.4 it can only be reached through a request interceptor.UI.access. The same check is applied to the signal result notifier and to the background-change flag.Root cause
ElementEffect.enableEffectruns the command inline whenUI.getCurrent() == ui. Its fallback inside the dispatcher has the same check.VaadinService.requestEndfiresRequestEndedEventand calls the interceptors whileCurrentInstancestill holds the UI, but after the request handler has released the session lock.VaadinService(createCurrentUiDispatcher) andEffect.onDependencyChange(the background-change flag) use the same UI-only check.Artur- commentedon Nov 23, 2026
@totally-not-ai isn't this the real bug that the current UI is set when session is not locked? That sounds inconsistent with everything else?
totally-not-ai commentedon Nov 23, 2026
@Artur- Yes, I agree. The lock check in the effect only treats the symptom. The real inconsistency is that the request's UI stays current after the lock is released.
Request handlers set the current UI while they hold the lock, for example in
findUIand in bootstrap. Nothing restores it when they unlock. It is only cleared byCurrentInstance.clearAll()at the very end ofrequestEnd. So response writing,VaadinRequestInterceptor.requestEndandRequestEndedEventlisteners all run with a current UI but without the lock.Everywhere else, the current UI exists only while the lock is held:
UI.accessandVaadinSession.accessset it and restore it around the locked work.Changing this is a behaviour change. A
requestEndinterceptor or request end listener that readsUI.getCurrent()today would getnull.Next step: restore the previous current UI when the request handler releases the session lock. This covers the UIDL, heartbeat and bootstrap handlers, and push. Please answer:
main/25.4, and backport only the effect check to 25.0–25.3, where the interceptor change would be riskier? (recommended: yes)One reply from a maintainer mentioning
@totally-not-aiwith the answers is enough for me to update fix: run signal effects inline only when session is locked #27188. Until then, that PR contains only the effect check.docs: tie current instances to the session lock (#27198) (CP: 25.4)
fix: fire session lock released event without current UI (#27439) (CP…
fix: restore current instances when request handlers unlock session (#…
fix: run signal effects inline only when session is locked (#27460) (…
docs: tie current instances to the session lock (vaadin#27198)
fix: restore current instances when request handlers unlock session (v…
fix: fire session lock released event without current UI (vaadin#27439)
fix: run signal effects inline only when session is locked (vaadin#27460
manolo commentedon Dec 2, 2026
Related: #27446 is the same rule broken another way, UI serialization making the UI current without the session lock, which also reaches the inline effect branch.