-
Notifications
You must be signed in to change notification settings - Fork 1.1k
SerializationFailedException after re-deploying with changed session object #280
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
Comments
You have a number of options:
public class InvalidClassExceptionSafeRepository<S extends ExpiringSession> implements SessionRepository<S> {
private final SessionRepository<S> repository;
public InvalidClassExceptionSafeRepository(SessionRepository<S> repository) {
this.repository = repository;
}
public S getSession(String id) {
try {
return repository.getSession(id);
} catch(SerializationException e) {
delete(id);
return null;
}
}
public S createSession() {
return repository.createSession();
}
public void save(S session) {
repository.save(session);
}
public void delete(String id) {
repository.delete(id);
}
} @Primary
@Bean
public SessionRepository primarySessionRepository(RedisOperationsSessionRepository delegate) {
return new InvalidClassExceptionSafeRepository(delegate);
} |
Thanks for the input. I'm planning to go with Option 4, to decorate the SessionRepository. I added the code you have given. However, even though the bean is loaded, none of the methods are called during creating or getting the session. Is there any other bean or configuration that I might be missing? I am instantiating the bean in HttpSessionConfig
|
Try adding |
Tried that as well. The bean does get instantiated. However it seems that internally Spring Session still uses the sessionRepository bean (instead of primarySessionRepository). That makes sense considering the fact that sessionRepository bean is of the type RedisOperationsSessionRepository, while we're creating a bean of the type SessionRepository.
|
That shouldn't matter since the classes that consume it use the interface. I think the problem may be that you need to specify the generic types: @Primary
@Bean
@SuppressWarnings({ "rawtypes", "unchecked" })
public SessionRepository<? extends ExpiringSession> primarySessionRepository(RedisOperationsSessionRepository delegate) {
return new InvalidClassExceptionSafeRepository(delegate);
} This is necessary because springSessionRepositoryFilter requests a |
No luck :(. |
Sorry...I missed your updated comment somehow. Did you end up getting this resolved? |
Related #200 |
No, haven't looked into this in a while. I'll check again. |
Ran into the same issue, opted for the solution with the Repository-wrapper, however I had to adapt it since the repository Here is my workaround-version:
It's not as nice, since i have to duplicate the Thanks rwinch for the initial suggestion! |
@NoUsername How do you instantiate the bean? I used
However, when the session is created the bean is not used |
Sorry for the long delay, this is how i instantiate it:
|
Clearing the session if an serialization exception occurs + warning log seems a reasonable default behavior. As it is now you have to clear the session manually or your application will break. |
I think that a strategy would be ideal for serialization errors. Ideally default behaviour would be great with warn + log. Having a 500 is too harsh. |
I don't think that we can make ignoring any exception a default. However, I think that providing a class similar to |
While deleting session object I had to use prefix of spring session i.e "spring:sessions:" like below to make it work.
Thanks |
I tried all the suggestions mentioned above, nothing worked for me. |
When using this solution, I had huge performance issues when multiple users started using the app. |
After a re-deploy, because of spring-sessions, the sessions are alive. But if a class that has an object instance in the session changes, we get the following error.
LogLevel=ERROR; msg=Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception; category=o.a.c.c.C.[.[.[.[dispatcherServlet];
org.springframework.data.redis.serializer.SerializationException: Cannot deserialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to deserialize payload. Is the byte array a result of corresponding serialization for DefaultDeserializer?; nested exception is java.io.InvalidClassException: sb.se.domain.BillingPlanPromo; local class incompatible: stream classdesc serialVersionUID = 1760563701508754914, local class serialVersionUID = 140820402964695138
This error does make sense. However, the users ends up seeing a 500 page. Two solutions come to my mind here:
Is any of these solutions (or any other) possible?
The text was updated successfully, but these errors were encountered: