Skip to content

docs: note SessionLockReleasedEvent listeners run without a current UI - #6790

Merged
peholmst merged 3 commits into
mainfrom
doc-bot/vaadin-flow/27439-2170e7fbc3d6df87
Dec 2, 2026
Merged

peholmst merged 3 commits into
mainfrom
doc-bot/vaadin-flow/27439-2170e7fbc3d6df87

Conversation

@vaadin-bot

Copy link
Copy Markdown
Contributor

Documentation for vaadin/flow#27439 by @totally-not-ai[bot].

Note

The source pull request is merged, so this documentation describes the final shape of the change. Please review it and mark it ready for review.

Change categories: BEHAVIOR_CHANGE

File Change
articles/flow/advanced/session-lock-and-rpc-listeners.adoc Documents that SessionLockReleasedEvent listeners (and the deprecated SessionLockListener.lockReleased) run after the lock is released without a current UI, and that session access from such a listener re-fires the release event, so a listener that accesses the session on every release must guard against it.

Auto-generated by the Documentation Bot — review before merging.

Generated by Documentation Bot for #27439 · agent · 86.1 AIC · ⊞ 11.7K · ◷

  • expires on Dec 26, 2026, 4:58 PM UTC

Documents that SessionLockReleasedEvent listeners run after the lock is
released without a current UI, and that session access from such a
listener re-fires the release event, on the Service Event Bus page.

Documents vaadin/flow#27439 (`c6ce6f818e6ed2cdb36f12e1e23bae7b1907c10e`).
@github-actions

Copy link
Copy Markdown
Contributor

Preview Deployment

This PR has been deployed for preview.

URL: https://docs-preview-pr-6790.fly.dev

Changed pages

Added content is highlighted in green; removed content is marked in red on each page.

Built from 7b83972

@peholmst
peholmst marked this pull request as ready for review December 2, 2026 07:44

@vaadin-review-bot vaadin-review-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the changes — left 2 comments.

Finding
⚠️ The signal path does not re-fire the lock events on the releasing thread
📐 A three-item list inside a 55-word sentence breaks the stated writing convention

It can also happen after the Vaadin session has been removed from the HTTP session, since the lock keeps the session only through a weak reference.

[classname]`SessionLockReleasedEvent` listeners run on the thread that released the lock, after the release, so they don't hold the session lock and [methodname]`UI.getCurrent()` returns `null`; a listener that needs a UI keeps its own reference to it instead of reading the current instance.
Any session access such a listener makes -- [methodname]`UI.access()`, [methodname]`VaadinSession.access()`, or changing a signal that one of the UI's effects depends on, since the effect then runs through [methodname]`UI.access()` -- takes the lock again and fires these events again, on the same thread if the lock is free or on whichever thread holds it otherwise.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ The signal path does not re-fire the lock events on the releasing thread

on the same thread if the lock is free or on whichever thread holds it otherwise

This holds for a direct [methodname]UI.access() or [methodname]VaadinSession.access(), which call ensureAccessQueuePurged() and tryLock() on the calling thread. It does not hold for the signal case the same sentence lists. An element effect dispatches through SignalEnvironment.getDefaultEffectDispatcher() and only then calls ui.access() (flow-server/src/main/java/com/vaadin/flow/dom/ElementEffect.java:275-300), and Flow's environment returns VaadinService.getExecutor() as the effect dispatcher (flow-server/src/main/java/com/vaadin/flow/server/VaadinService.java:571-573). Since [methodname]UI.getCurrent() is null in the listener, isCurrentAndLocked() is false, so the lock is taken on an executor thread.

Consider splitting the thread claim off and scoping it: the two access() calls re-lock on the releasing thread, while a signal change is dispatched through the service executor and re-locks there.

session-lock-and-rpc-listeners.adoc:142 · accuracy

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. The direct UI.access() and VaadinSession.access() calls are now a separate list item: they take the lock on the calling thread if it is free, or on whichever thread holds it otherwise. For a signal change, the page now says the effect is usually queued to the service executor, which runs it through UI.access(), so the lock is taken on the executor thread if it is free.

It can also happen after the Vaadin session has been removed from the HTTP session, since the lock keeps the session only through a weak reference.

[classname]`SessionLockReleasedEvent` listeners run on the thread that released the lock, after the release, so they don't hold the session lock and [methodname]`UI.getCurrent()` returns `null`; a listener that needs a UI keeps its own reference to it instead of reading the current instance.
Any session access such a listener makes -- [methodname]`UI.access()`, [methodname]`VaadinSession.access()`, or changing a signal that one of the UI's effects depends on, since the effect then runs through [methodname]`UI.access()` -- takes the lock again and fires these events again, on the same thread if the lock is free or on whichever thread holds it otherwise.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 A three-item list inside a 55-word sentence breaks the stated writing convention

CONVENTIONS.md (Writing): "When a sentence that you add or change is too long, split it. Give an aside or an example its own sentence. When a list of three or more items makes the sentence long, turn it into a bulleted list."

Line 142 is about 55 words and puts a three-item list inside an em-dash aside, with a further since clause nested in the third item. Subject and verb ("Any session access … takes the lock again") are 25 words apart. Line 141 is about 45 words joined by a semicolon.

A bulleted list of the three access kinds, with the thread and the loop warning as separate sentences, would carry the same facts. Vale does not report this: SentenceLength and Semicolons are suggestion level, and the pull request config sets MinAlertLevel = warning.

session-lock-and-rpc-listeners.adoc:142 · conventions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split it. The three kinds of access are now a bulleted list, and the thread details and the loop warning are separate sentences. The semicolon sentence before it is now three sentences.

A signal change runs the effect through UI.access() on a service executor
thread, not on the thread that released the lock. List the kinds of
access, and split the long sentences.
The executor thread takes the lock only when it's free; otherwise the
thread that holds the lock runs the effect. Without a current service,
the effect isn't queued to the executor at all.
@peholmst
peholmst merged commit c1cdb3e into main Dec 2, 2026
10 of 11 checks passed
@peholmst
peholmst deleted the doc-bot/vaadin-flow/27439-2170e7fbc3d6df87 branch December 2, 2026 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants