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
Improve handling of missing JSF session in SessionScope [SPR-12402] #17010
Comments
Andrei Ivanov commented My workaround (and possible solution): public class CustomSessionScope extends SessionScope {
@Override
public Object get(String name, ObjectFactory<?> objectFactory) {
Object mutex = RequestContextHolder.currentRequestAttributes().getSessionMutex();
if (mutex == null) {
// During the session restore phase at server startup, there is no session yet available.
return null;
}
return super.get(name, objectFactory);
}
} Any thoughts? |
Juergen Hoeller commented How could the session mutex ever be |
Andrei Ivanov commented Well, I mention the scenario in the description: when Tomcat starts, it tries to restore those sessions from the serialized files on disk, which triggers this exception. |
Juergen Hoeller commented Sure, and I'd love to address this... but technically, even in such a scenario, I don't see how In other words, it's not obvious to me why your suggested workaround does the job for you. How exactly does it arrive at |
Juergen Hoeller commented Also, returning FWIW, both |
Andrei Ivanov commented When starting Tomcat and the web app gets deployed, this method gets called: @Override
public Object getSessionMutex() {
// Enforce presence of a session first to allow listeners
// to create the mutex attribute, if any.
Object session = getExternalContext().getSession(true);
Object mutex = getExternalContext().getSessionMap().get(WebUtils.SESSION_MUTEX_ATTRIBUTE);
if (mutex == null) {
mutex = session;
}
return mutex;
}
This leads to the mutex being This is a corner case, I admit that it's not nice for these methods to return null, but that's how it happens :) |
Juergen Hoeller commented It seems appropriate to tighten our |
Juergen Hoeller commented I've rolled this in as suggested above, with |
Andrei Ivanov commented I ran a test, seems to work fine now :) |
Andrei Ivanov opened SPR-12402 and commented
I have some JSF beans managed by Spring using
@Configurable
and compile time weaving.Then I have a session scoped bean:
When Tomcat shuts down, it persists the active sessions.
When it starts it tries to restore those sessions, which triggers this exception:
As there is no current request, this exception gets thrown.
I'm hoping that a better way of handling this scenario can be implemented.
Affects: 4.0.7
Referenced from: commits 042d8d0
The text was updated successfully, but these errors were encountered: