Repository navigation
docs: note SessionLockReleasedEvent listeners run without a current UI - #6790
Conversation
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`).
Preview DeploymentThis PR has been deployed for preview. URL: https://docs-preview-pr-6790.fly.dev Changed pagesAdded content is highlighted in green; removed content is marked in red on each page.
Built from 7b83972 |
vaadin-review-bot
left a comment
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
📐 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
There was a problem hiding this comment.
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.
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
articles/flow/advanced/session-lock-and-rpc-listeners.adocSessionLockReleasedEventlisteners (and the deprecatedSessionLockListener.lockReleased) run after the lock is released without a currentUI, 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.