Repository navigation
fix: fire session lock released event without current UI (#27439) (CP: 25.4) - #27453
Conversation
…: 25.4) Part of #27187 Related to #27201, #27198 **Behavior deviation** · flow-server · apps with `SessionLockReleasedEvent` listeners (or the deprecated `SessionLockListener.lockReleased`) A session lock released listener runs after the lock is released, but the UI that the locked work made current, for example inside `UI.access`, was still current. A listener that changed a shared signal then ran that UI's signal effects without the lock, and they failed with "Cannot access state in VaadinSession or UI without locking the session". Released listeners now run with no current UI, so such effects go through `UI.access`. **Risks:** -⚠️ Behaviour change: `UI.getCurrent()` returns `null` in released listeners. Before, it returned a UI whose session the thread no longer held, so code using it there was not safe. - 🧵 Threading: restores the rule that a current UI means its session is locked by this thread, for the one callback that runs inside `unlock()` after the release. - ✅ No public API, security, memory, serialization or performance impact. **Context.** The released event is fired from the lock itself, after the real release. `UI.accessSynchronously` and the request handlers restore the previous current instances only after `unlock()` returns, so the listeners ran in that window. - The session lock clears the current UI while it fires the released event and restores it afterwards, so callers see the same current instances as before once `unlock()` returns. - Documented in `SessionLockReleasedEvent` and `SessionLockListener.lockReleased` that listeners run without the lock and without a current UI, and that any session access from a listener, signal changes that run effects included, fires the released event again, so a listener must skip the release caused by its own access. - Updated `guidelines/architecture.md`, which said the window after `unlock()` runs no application code. - Added a test that a released listener sees no current UI and no lock, and that the caller's UI is current again after unlocking. Working on behalf of @Artur- --------- Co-authored-by: totally-not-ai[bot] <290682512+totally-not-ai[bot]@users.noreply.github.com>
The release listener now runs with no current UI, bracketed around the eventsequenceDiagram
participant C as locked work (e.g. UI.access task)
participant L as InstrumentedReentrantLock.unlock()
participant E as SessionLockReleasedEvent listener
C->>L: unlock()
L->>L: super.unlock() releases the lock
L->>L: UI.setCurrent(null) (new)
L->>E: fireEventInReverseOrder(SessionLockReleasedEvent)
Note over E: UI.getCurrent() is null here, was: the caller's UI, though the lock was already released
E-->>L: listener returns
L->>L: UI.setCurrent(ui) restores the caller's UI (new)
L-->>C: unlock() returns
Diagram Bot draws the mechanism this pull request touches; it does not review the change. Verify it against the diff.
|
|
This PR is eligible for auto-merging policy, so it has been approved automatically. If there are pending conditions, auto merge (with 'squash' method) has been enabled for this PR [Message is sent from bot] |
|
Test Results 1 705 files 1 795 suites 2h 13m 32s ⏱️ Results for commit 02c01b3. |



This PR cherry-picks changes from the original PR #27439 to branch 25.4.