Skip to content

Scoped proxies are fragile with respect to serialization [SPR-14117] #18689

New issue

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

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

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Apr 5, 2016 · 3 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Apr 5, 2016

Dave Syer opened SPR-14117 and commented

A scoped proxy (e.g. in @Scope("session") with @Lazy) carries a reference to a "serialization id" for the BeanFactory. This is in case, when it is deserialized, it needs to inject a dependency from the Spring context. As such, that can be quite useful, but it is also brittle, and not always necessary, since not all beans have dependencies to re-inject, and sometimes you want to share an instance between two contexts that don't naturally have the same serialization id.

There's quite a bit of discussion in one or two github issues related to Spring Cloud, Spring Boot and Spring OAuth2 (e.g. spring-attic/spring-security-oauth#705).

In the OAuth2 case we are only using @Scope("session") to keep the state segregated between concurrent users, and the data held in those beans is naturally serializable without any reference to the BeanFactory. I imagine this could be quite common, and I would like a way to annotate (or have Spring detect) that this is the case, so that the serialized form of the object does not contain a BeanFactory reference if it is not going to be needed.


Reference URL: spring-attic/spring-security-oauth#705

Issue Links:

Referenced from: commits 4024b2f

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

The serialized representation of such a BeanFactory reference is quite trivial, so I suppose this is not about the computation effort or the memory requirement... but more about the failure to deserialize when the serialization id isn't resolvable, even when the deserialized BeanFactory isn't actually needed? If that is the case, do you have a use case plus stacktrace handy for such a deserialization failure?

@spring-projects-issues
Copy link
Collaborator Author

Dave Syer commented

Correct, it's not about computation or memory - for the kinds of objects I am interested in there is literally no use for the serialization id anyway (it's just noise). There's a link to another gh issue with a stack trace in the reference URL (here's the link: spring-cloud/spring-cloud-commons#93). The use case that sparked the debate was sharing a session between 2 apps using Spring Session, and having a @Scope("session") object blow up when it crossed the boundary.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

We might be able to make this more lenient, deserializing to a dummy BeanFactory instead of throwing an IllegalStateException. After all, the intent was just to reconnect to the same BeanFactory if available; if not available, we can proceed on a best-effort basis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants