You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
UI locking: per-UI lock core behind an experimental feature flag #27582
The core of per-UI locking: requests for one UI no longer block other UIs in the same session.
Rules (to be agreed in #24187 before implementation)
Lock order: a thread holding a UI lock may take the session lock. A thread holding a session lock may never wait for a UI lock.
Deterministic failures: accessSynchronously / lock() on a UI while holding the session lock throws IllegalStateException every time, not only when the UI happens to be busy (no tryLock() heuristics). The same applies to holding a UI lock of another session, so verifyNoOtherSessionLocked must also treat UI locks as held.
Session state: holding a UI lock does not give access to session state. VaadinSession.checkHasLock() keeps requiring the session lock, and app code locks the session explicitly for attributes.
Whether VaadinSession.getCurrent() is set during UI-locked handling.
Scope
Register UI locking as an experimental feature in FeatureFlags, so it is clearly marked as "use at your own risk" while the remaining parts land.
Per-UI ReentrantLock and access queue. UI.access / accessSynchronously use them, and releasing the UI lock runs that UI's tasks and pushes that UI only.
UIDL and heartbeat requests are handled with only the UI lock. Bootstrap creates and adds the UI while holding both locks, in the allowed order.
Session cleanup paths that run under the session lock (closing inactive UIs, removing closed UIs, session destroy) must not wait for UI locks.
Acceptance criteria
Unit tests covering each rule above, including the cross-session case (thread holding a UI lock of session X accessing a UI of session Y fails instead of deadlocking).
With the flag off, behaviour is unchanged.
One integration test with two UIs in one session, where a slow handler in one tab does not block the other.
Main risk: deadlocks and races between the session lock and UI locks. Rules 1–2 (fixed lock order, and always failing when the order is wrong) are what prevent them. Session cleanup paths that hold the session lock must never wait for a UI lock.
Overlap: community PR Feat/UI locking #26804 already implements much of this scope behind a flag, in one large change. Reuse its parts, with credit, rather than starting from scratch.
One reply from a maintainer on this issue that mentions @totally-not-ai (e.g. @totally-not-ai 1: yes, 2: yes, 3: yes) is enough for me to open a PR once the prerequisites are in. Others are welcome to weigh in.
Where the change lands
UI: per-UI ReentrantLock and access queue. Release runs that UI's queued tasks and pushes that UI only.
VaadinService.verifyNoOtherSessionLocked, FutureAccess: treat a held UI lock like a held session lock, so the cross-session case fails instead of deadlocking.
UidlRequestHandler, HeartbeatHandler: currently SynchronizedRequestHandlers that take the session lock. With the flag on, they take only the UI lock.
BootstrapHandler / VaadinSession.addUI: create and add the UI holding both locks, UI lock first.
VaadinService cleanup (closeInactiveUIs, removeClosedUIs, session destroy): currently calls ui.accessSynchronously under the session lock. This must change so it never blocks on a UI lock, e.g. queue the work with ui.access or use a non-blocking path.
Rule 2: the summary on Locking issue when using Multiple Tabs in a near Real-Time-Application #24187 defines "holding a session lock" as "VaadinSession.getCurrent() is set". That definition only works if rule 4 leaves getCurrent() unset during UI-locked handling, so rules 2 and 4 should be decided together.
Rule 3: keeps VaadinSession.checkHasLock() strict. Code that reads and then writes session attributes, and @VaadinSessionScope beans, must lock the session explicitly. This is the main migration cost for apps that turn on the flag. Spring/CDI follow-ups are in UI locking: Spring, CDI, signals and setLocale integrations #27584.
UI.access stays allowed while holding the session lock, because it queues the task instead of blocking.
Activity
totally-not-ai commentedon Dec 1, 2026
Triage: valid enhancement, planned sub-task of #24187. Not on the default branch yet, and it can't start until its prerequisites land.
Where it fits: this is the step that actually changes behaviour: UIDL and heartbeat requests run with only the UI lock, so a slow tab no longer blocks other tabs in the same session. It builds on the UI lock API (UI locking: add UI lock API that delegates to the session lock #27580) and on thread-safe session internals (UI locking: make VaadinSession internals thread-safe #27581). Both are still open.
Main risk: deadlocks and races between the session lock and UI locks. Rules 1–2 (fixed lock order, and always failing when the order is wrong) are what prevent them. Session cleanup paths that hold the session lock must never wait for a UI lock.
Overlap: community PR Feat/UI locking #26804 already implements much of this scope behind a flag, in one large change. Reuse its parts, with credit, rather than starting from scratch.
Next step: implement the per-UI lock and access queue behind an experimental flag, after UI locking: add UI lock API that delegates to the session lock #27580 and UI locking: make VaadinSession internals thread-safe #27581 are merged. A maintainer needs to settle these first:
VaadinSession.getCurrent()unset during UI-locked handling? (recommended: yes, as in the maintainer summary on Locking issue when using Multiple Tabs in a near Real-Time-Application #24187)One reply from a maintainer on this issue that mentions
@totally-not-ai(e.g.@totally-not-ai 1: yes, 2: yes, 3: yes) is enough for me to open a PR once the prerequisites are in. Others are welcome to weigh in.Where the change lands
UI: per-UIReentrantLockand access queue. Release runs that UI's queued tasks and pushes that UI only.VaadinService.verifyNoOtherSessionLocked,FutureAccess: treat a held UI lock like a held session lock, so the cross-session case fails instead of deadlocking.UidlRequestHandler,HeartbeatHandler: currentlySynchronizedRequestHandlers that take the session lock. With the flag on, they take only the UI lock.BootstrapHandler/VaadinSession.addUI: create and add the UI holding both locks, UI lock first.VaadinServicecleanup (closeInactiveUIs,removeClosedUIs, session destroy): currently callsui.accessSynchronouslyunder the session lock. This must change so it never blocks on a UI lock, e.g. queue the work withui.accessor use a non-blocking path.FeatureFlags: register the experimental flag. Note that Locking issue when using Multiple Tabs in a near Real-Time-Application #24187 proposed aDeploymentConfigurationoption, and UI locking: forEachUi helper, documentation and configuration property #27585 covers the configuration property, so the flag is temporary until that lands.Notes on the rules
VaadinSession.getCurrent()is set". That definition only works if rule 4 leavesgetCurrent()unset during UI-locked handling, so rules 2 and 4 should be decided together.VaadinSession.checkHasLock()strict. Code that reads and then writes session attributes, and@VaadinSessionScopebeans, must lock the session explicitly. This is the main migration cost for apps that turn on the flag. Spring/CDI follow-ups are in UI locking: Spring, CDI, signals and setLocale integrations #27584.UI.accessstays allowed while holding the session lock, because it queues the task instead of blocking.