Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Vaadin Kubernetes Kit throws an exception while handling transient beans with scope “vaadin-ui” or “vaadin-session” #140

Closed
myronenkom opened this issue Sep 13, 2024 · 1 comment · Fixed by #152
Assignees

Comments

@myronenkom
Copy link

myronenkom commented Sep 13, 2024

Hello,
Recently, we’ve encountered an issue related to session serialization in the Vaadin Kubernetes Kit. The problem occurs during the serialization of a bean that injects another bean with a scope of either “vaadin-ui” or “vaadin-session.”

Here’s a brief overview of the issue:

  1. During serialization, the com.vaadin.kubernetes.starter.sessiontracker.serialization.TransientInjectableObjectOutputStream attempts to handle the transient injectable fields.
  2. At some point, it calls SpringTransientHandler#detectBean to retrieve the injectable bean from the context.
  3. The context then tries to handle the scope and invokes the VaadinUIScope or VaadinSessionScope post processor.
  4. However, this process fails because it requires access to the VaadinSession, which is not present in the thread where serialization is performed.
  5. As a result, an exception is thrown at com.vaadin.flow.spring.scopes.AbstractScope.java:73.

Here is the project to reproduce the issue https://github.com/myronenkom/kubernates-kit-issue

Stack trace attached
Session Serialization issue stack trace.txt

@mcollovati
Copy link
Contributor

Serialization and deserialization of Vaadin scoped beans into transient fields fails because VaadinSession and UI thread locals are not set, causing an exception when accessing the bean store to detect/retrieve the bean reference.

The serialization part can be fixed in flow (see linked issue) by setting the thread locals in serialiaziont write hooks.
However, the deserialization part should be fixed in Kubernetes Kit because injection of transient fields happens after deserialization of the session attributes.

The fix could be to add VaadinSession and UI fields to TransientAwareHolder (should not have a big impact on the overall size of the serialized data), so that during injection it should be possible to set the thread locals.
In addition, VaadinSessionScope locks VaadinSession, but after deserialization the lock instance is not yet set. So, a temporary lock must be forced into the VaadinSession instance while applying field injections, and removed immediately after.

johannest added a commit to johannest/kubernetes-kit that referenced this issue Sep 18, 2024
Fixes from @mcollovati applied: inject transient objects with thread local UI and VaadinSession
@mcollovati mcollovati self-assigned this Oct 30, 2024
mcollovati added a commit to vaadin/flow that referenced this issue Nov 4, 2024
Makes sure that VaadinSession and UI thread locals are available during
both serialization and deserialization, to allow other libraries to
perform inspection and injection of Vaadin scoped beans.

Also refactors VaadinRouteScope to be independent from VaadinService
when fetching RouteScopeOwner annotation for the bean, and replaces
VaadinSession.unlock() calls with direct access to the lock instance
to prevent unwanted push during bean lookup.

Fixes #19967
Part of vaadin/kubernetes-kit#140
mcollovati added a commit to vaadin/flow that referenced this issue Nov 4, 2024
Makes sure that VaadinSession and UI thread locals are available during
both serialization and deserialization, to allow other libraries to
perform inspection and injection of Vaadin scoped beans.

Also refactors VaadinRouteScope to be independent from VaadinService
when fetching RouteScopeOwner annotation for the bean, and replaces
VaadinSession.unlock() calls with direct access to the lock instance
to prevent unwanted push during bean lookup.

Fixes #19967
Part of vaadin/kubernetes-kit#140
mcollovati added a commit that referenced this issue Nov 4, 2024
Vaadin scoped beans requires VaadinSession and UI thread locals to be set
in order to lookup beans.
This change tracks Vaadin scoped beans during serialization and makes sure
that required thread locals are set during deserialization.

The serialVersionUID added to TransientDescriptor should keep it compatible
with older version, preventing deserialization of previous data to fail.

Fixes #140
Requires vaadin/flow#20394
mshabarov added a commit to vaadin/flow that referenced this issue Nov 7, 2024
Makes sure that VaadinSession and UI thread locals are available during
both serialization and deserialization, to allow other libraries to
perform inspection and injection of Vaadin scoped beans.

Also refactors VaadinRouteScope to be independent from VaadinService
when fetching RouteScopeOwner annotation for the bean, and replaces
VaadinSession.unlock() calls with direct access to the lock instance
to prevent unwanted push during bean lookup.

Fixes #19967
Part of vaadin/kubernetes-kit#140

Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com>
vaadin-bot pushed a commit to vaadin/flow that referenced this issue Nov 7, 2024
Makes sure that VaadinSession and UI thread locals are available during
both serialization and deserialization, to allow other libraries to
perform inspection and injection of Vaadin scoped beans.

Also refactors VaadinRouteScope to be independent from VaadinService
when fetching RouteScopeOwner annotation for the bean, and replaces
VaadinSession.unlock() calls with direct access to the lock instance
to prevent unwanted push during bean lookup.

Fixes #19967
Part of vaadin/kubernetes-kit#140

Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com>
mcollovati added a commit to vaadin/flow that referenced this issue Nov 7, 2024
Makes sure that VaadinSession and UI thread locals are available during
both serialization and deserialization, to allow other libraries to
perform inspection and injection of Vaadin scoped beans.

Also refactors VaadinRouteScope to be independent from VaadinService
when fetching RouteScopeOwner annotation for the bean, and replaces
VaadinSession.unlock() calls with direct access to the lock instance
to prevent unwanted push during bean lookup.

Fixes #19967
Part of vaadin/kubernetes-kit#140

Co-authored-by: Marco Collovati <marco@vaadin.com>
Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com>
mcollovati added a commit to vaadin/flow that referenced this issue Nov 7, 2024
Makes sure that VaadinSession and UI thread locals are available during
both serialization and deserialization, to allow other libraries to
perform inspection and injection of Vaadin scoped beans.

Also refactors VaadinRouteScope to be independent from VaadinService
when fetching RouteScopeOwner annotation for the bean, and replaces
VaadinSession.unlock() calls with direct access to the lock instance
to prevent unwanted push during bean lookup.

Fixes #19967
Part of vaadin/kubernetes-kit#140

Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com>
mshabarov added a commit to vaadin/flow that referenced this issue Nov 12, 2024
Makes sure that VaadinSession and UI thread locals are available during
both serialization and deserialization, to allow other libraries to
perform inspection and injection of Vaadin scoped beans.

Also refactors VaadinRouteScope to be independent from VaadinService
when fetching RouteScopeOwner annotation for the bean, and replaces
VaadinSession.unlock() calls with direct access to the lock instance
to prevent unwanted push during bean lookup.

Fixes #19967
Part of vaadin/kubernetes-kit#140

Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com>
tamasmak added a commit that referenced this issue Nov 27, 2024
Vaadin scoped beans requires VaadinSession and UI thread locals to be set
in order to lookup beans.
This change tracks Vaadin scoped beans during serialization and makes sure
that required thread locals are set during deserialization.

The serialVersionUID added to TransientDescriptor should keep it compatible
with older version, preventing deserialization of previous data to fail.

Fixes #140
Requires vaadin/flow#20394

Co-authored-by: Tamas Mak <tamas@vaadin.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants