Skip to content
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

Fixed stale local session issue after failover #101

Merged
merged 2 commits into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private void handleTomcatSessionChange(Request request) throws IOException {
int index = currentSessionId.indexOf(".");
String requestedJvmRoute = null;
if (index > 0) {
requestedJvmRoute = currentSessionId.substring(index + 1, currentSessionId.length());
requestedJvmRoute = currentSessionId.substring(index + 1);
}

if (requestedJvmRoute == null || requestedJvmRoute.equals(jvmRoute)) {
Expand All @@ -54,5 +54,6 @@ private void handleTomcatSessionChange(Request request) throws IOException {

String newSessionId = sessionManager.updateJvmRouteForSession(currentSessionId, jvmRoute);
request.changeSessionId(newSessionId);
request.getSession().invalidate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
} else if (req.getRequestURI().endsWith("read-custom-attribute")) {
CustomAttribute value = (CustomAttribute) session.getAttribute("key");
resp.getWriter().write(value == null ? "null" : value.toString());
} else if (req.getRequestURI().endsWith("get-session-id")) {
resp.getWriter().write(req.getSession().getId());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,13 @@ public void test_LastAccessTime() throws Exception {
}

@Test(timeout = 80000)
public void testFailover() throws Exception {
public void testFailoverWithNoStaleSession() throws Exception {
CookieStore cookieStore = new BasicCookieStore();
String value = executeRequest("read", SERVER_PORT_1, cookieStore);
assertEquals("null", value);

executeRequest("write", SERVER_PORT_1, cookieStore);
String oldSessionId = executeRequest("get-session-id", SERVER_PORT_1, cookieStore);

instance1.stop();

Expand All @@ -157,8 +158,12 @@ public void testFailover() throws Exception {
hzInstance1.shutdown();
}

String newSessionId = executeRequest("get-session-id", SERVER_PORT_2, cookieStore);
//The session id should be different after failover because of the changed jvmRoute
assertNotEquals(oldSessionId, newSessionId);
value = executeRequest("read", SERVER_PORT_2, cookieStore);
assertEquals("value", value);

}

// @Test
Expand Down