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: make VaadinSession internals thread-safe #27581
Make the framework's own VaadinSession internals safe to touch from more than one thread, as a preparation for UI locking. No behaviour change.
Scope
Store uIs as a ConcurrentHashMap inside VaadinSession. UIs keep living in the session (no service-wide registry), so they are still collected together with the session.
Use atomics or volatile for the request timing fields, errorHandler, browser and state, and a concurrent map in StreamResourceRegistry.
Keep the serialized form compatible: don't change the declared types of serialized fields such as nextUIId and requestHandlers, or handle the old form in readObject.
Leave Attributes alone. Component data (ComponentUtil.setData) is UI state, and session attributes stay behind the session lock.
Acceptance criteria
No behaviour change.
A session serialized with the previous version still deserializes (test for it).
No extra memory or locking cost for component data.
Main caveat — serialization: no Flow class declares a serialVersionUID. The computed one for VaadinSession already differs between 25.3.9 and 25.4.0-beta2, so sessions don't survive a minor upgrade today. Adding volatile to a serialized field changes it again. So "a session serialized with the previous version still deserializes" only holds if we pin the UID, or if we read it as "the stream layout is unchanged".
Second caveat: the registry map is a final serialized field. Reading an old stream gives back a plain HashMap. To swap in a concurrent map on read, we must drop final, and that changes the registry's computed UID too. That UID has been stable across releases so far.
Next step: make the fields concurrent-safe and keep the stream layout: the UI map is still written as a HashMap, and both maps are converted when read. A maintainer needs to settle three points:
Read the criterion as "same stream layout, round-trip test" rather than cross-version binary compatibility? (recommended: yes)
Pin serialVersionUID on VaadinSession / StreamResourceRegistry? (recommended: no — that is a project-wide policy change, best handled in its own issue)
OK to drop final on the registry map so it can be converted on read? (recommended: yes)
One reply from a maintainer on this issue mentioning @totally-not-ai (e.g. @totally-not-ai 1: yes, 2: no, 3: yes) is enough for me to open a PR. Others are welcome to weigh in.
Details
UIs:uIs is already transient and written by hand in writeObject. Store a ConcurrentHashMap, write new HashMap<>(uIs) so the stream stays the same, and wrap the map in readObject. getUIs() stays an unmodifiable view. Iteration becomes weakly consistent instead of fail-fast, but the order is the same for small integer IDs.
Request timing:cumulativeRequestDuration += time is a read-modify-write, so volatile alone would lose updates once two UIs write it concurrently. An AtomicLong would change the declared field type. A VarHandlegetAndAdd on a volatile long keeps the type. Today all writers still hold the session lock, so this only matters once UI locking: per-UI lock core behind an experimental feature flag #27582 lands.
Not touched:nextUIId and requestHandlers keep their types, as the issue asks. They are only changed under the session lock, and UI creation stays a session-level operation. Attributes is left alone.
Test plan: deserialize a stream that has the old shape (HashMap for the UIs and for the registry). Check that the UIs and resources are restored and that a round trip keeps the same layout.
Let's drop the requirement for serialization compatibility. We aren't promising that in other cases either so there's no point in doing it here either.
Activity
totally-not-ai commentedon Dec 1, 2026
Triage: valid preparatory task. Not done on
mainyet. The scope is small and clear, but one acceptance criterion can't be met as written.Where it fits:
VaadinSession(UI map, request timing,errorHandler,browser,state) andStreamResourceRegistry. It is independent of UI locking: add UI lock API that delegates to the session lock #27580 and can land first.Main caveat — serialization: no Flow class declares a
serialVersionUID. The computed one forVaadinSessionalready differs between 25.3.9 and 25.4.0-beta2, so sessions don't survive a minor upgrade today. Addingvolatileto a serialized field changes it again. So "a session serialized with the previous version still deserializes" only holds if we pin the UID, or if we read it as "the stream layout is unchanged".Second caveat: the registry map is a
finalserialized field. Reading an old stream gives back a plainHashMap. To swap in a concurrent map on read, we must dropfinal, and that changes the registry's computed UID too. That UID has been stable across releases so far.Next step: make the fields concurrent-safe and keep the stream layout: the UI map is still written as a
HashMap, and both maps are converted when read. A maintainer needs to settle three points:serialVersionUIDonVaadinSession/StreamResourceRegistry? (recommended: no — that is a project-wide policy change, best handled in its own issue)finalon the registry map so it can be converted on read? (recommended: yes)One reply from a maintainer on this issue mentioning
@totally-not-ai(e.g.@totally-not-ai 1: yes, 2: no, 3: yes) is enough for me to open a PR. Others are welcome to weigh in.Details
uIsis alreadytransientand written by hand inwriteObject. Store aConcurrentHashMap, writenew HashMap<>(uIs)so the stream stays the same, and wrap the map inreadObject.getUIs()stays an unmodifiable view. Iteration becomes weakly consistent instead of fail-fast, but the order is the same for small integer IDs.cumulativeRequestDuration += timeis a read-modify-write, sovolatilealone would lose updates once two UIs write it concurrently. AnAtomicLongwould change the declared field type. AVarHandlegetAndAddon avolatile longkeeps the type. Today all writers still hold the session lock, so this only matters once UI locking: per-UI lock core behind an experimental feature flag #27582 lands.nextUIIdandrequestHandlerskeep their types, as the issue asks. They are only changed under the session lock, and UI creation stays a session-level operation.Attributesis left alone.checkHasLock(). Relaxing those checks belongs to UI locking: per-UI lock core behind an experimental feature flag #27582, not here.HashMapfor the UIs and for the registry). Check that the UIs and resources are restored and that a round trip keeps the same layout.Legioth commentedon Dec 1, 2026
Let's drop the requirement for serialization compatibility. We aren't promising that in other cases either so there's no point in doing it here either.