Skip to content

Commit

Permalink
Avoid extraneous call to SessionRespository.findById(...) in SessionR…
Browse files Browse the repository at this point in the history
…epositoryRequestWrapper.commitSession() due to premature cache clearing.

Closes gh-1731
  • Loading branch information
pferraro committed Dec 4, 2020
1 parent 2aae51b commit adfceed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,16 @@ private void commitSession() {
}
else {
S session = wrappedSession.getSession();
clearRequestedSessionCache();
SessionRepositoryFilter.this.sessionRepository.save(session);
String sessionId = session.getId();
if (!isRequestedSessionIdValid() || !sessionId.equals(getRequestedSessionId())) {
SessionRepositoryFilter.this.httpSessionIdResolver.setSessionId(this, this.response, sessionId);
try {
boolean sendSessionId = !isRequestedSessionIdValid() || !sessionId.equals(getRequestedSessionId());
SessionRepositoryFilter.this.sessionRepository.save(session);
if (sendSessionId) {
SessionRepositoryFilter.this.httpSessionIdResolver.setSessionId(this, this.response, sessionId);
}
}
finally {
clearRequestedSessionCache();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1313,8 +1313,8 @@ public void doFilter(HttpServletRequest wrappedRequest, HttpServletResponse wrap
}
});

// 3 invocations expected: initial resolution, after invalidation, after commit
verify(sessionRepository, times(3)).findById(eq(session.getId()));
// 3 invocations expected: initial resolution, after invalidation
verify(sessionRepository, times(2)).findById(eq(session.getId()));
verify(sessionRepository).deleteById(eq(session.getId()));
verify(sessionRepository).createSession();
verify(sessionRepository).save(any());
Expand Down

0 comments on commit adfceed

Please sign in to comment.