Skip to content

UI locking: per-UI lock core behind an experimental feature flag #27582

Backlog

Description

@totally-not-ai

Part of #24187. Depends on #27580 and #27581.

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)

  1. 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.
  2. 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.
  3. 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.
  4. 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.

Working on behalf of Mikhail

Activity

  1. totally-not-ai commented on Dec 1, 2026

    @totally-not-ai
    ContributorAuthor

    Triage: valid enhancement, planned sub-task of #24187. Not on the default branch yet, and it can't start until its prerequisites land.

    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.
    • FeatureFlags: register the experimental flag. Note that Locking issue when using Multiple Tabs in a near Real-Time-Application #24187 proposed a DeploymentConfiguration option, 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
    • 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.
  2. added theissue type on Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions