spring-projects / spring-session

Spring Session
https://spring.io/projects/spring-session
Apache License 2.0
1.86k stars 1.11k forks source link

SessionRepositoryFilter.SessionRepositoryRequestWrapper.commitSession() triggers extraneous call to SessionRespository.findById(...) #1731

Open pferraro opened 3 years ago

pferraro commented 3 years ago

Describe the bug For a valid session, SessionRepositoryFilter.SessionRepositoryRequestWrapper.commitSession() does the following:

  1. Clears cached values for references for requestedSessionCache, requestedSession, and requestedSessionId.
  2. Saves the state of the session
  3. If the requested session ID is not valid, or if the ID of the session changed from the requested session ID, then the session ID is sent to the client

However, since #1 already cleared the requested session cached values #3 requires a completely redundant call to SessionRepository.findById(...). Depending on the implementation, this can be unnecessarily expensive.

To Reproduce Use a tracer to detect calls to SessionRepository.findById(...). For a requested session, this is triggered twice, once at the beginning of the request, and again after the session is saved.

Expected behavior SessionRepository.findById(...) should be considered a potentially expensive operation, and only triggered when necessary. Clearing cached values after determining whether to send the session ID to the client (i.e. in a finally block) would solve the problem.

ashwaniagarwal226 commented 3 years ago

Hi All can i know in which release above fix will be available as i am facing the same issue mentioned above

anilgupta22 commented 3 years ago

Spring Session works great for session management but noticed lot of slowness because of this known issue. This is very urgent issue and blocker. Is there any official release date for this?

jlibasci commented 3 years ago

All this is a significant impact to performance for spring with apps that are using session management, Any chance we will see this fix pushed to the master branch in the next week or so.

Thanks in advance.

kunalsurana commented 2 years ago

This issue impacts the performance for large JSPs which has jsp:include where it tries to commit on each include but due to session getting cleared and call to getRequestedSessionId makes getSessionQuery again.