jbossjboss7.xjava-ee-7mod-cluster

MOD_CLUSTER - remove sticky session


I am using mod_cluster version 1.2.11.Final along with JBoss AS 7.2.0.Final (standalone-ha-full mode)

mod_cluster is setup with sticky sessions enabled, we typically have 2 or 3 JBoss servers running at the same time and rotate servers every evening to deploy updates

When we want to shutdown a JBoss server we disable all contexts for this node using the CLI command..

/subsystem=modcluster/:disable-context(virtualhost=my-webapp,context=/)

This stops any new sessions being routed to the node ok

We then wait 30min, but sometimes after this time there are still some sessions active

I have tried forcing them to logout and also removing the JSESSIONID cookie from the responses for these users, but they are still routed back to the same JBoss node (they are issued with a new JSESSIONID)

Is it possible to command mod_cluster to remove these sticky sessions?....or force them to another worker?

(I know I can just undeploy the application, but sometimes when there are a lot of active sessions remaining this causes the other server to crash with the sudden surge in demand)

Looking forward to hearing your suggestions


Solution

  • For anyone else having this problem, I created a workaround by registering a @WebFilter for the path /logout, within this filter I am invalidating the session and removing the JSESSIONID cookie, I then pass a redirect URI using a query param. The user is moved over to an alternative JBoss node and redirected to their original page. You just need to redirect them to /logout when the node shutdown is detected.

        @Override
        public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws ServletException, IOException {  
    
            HttpServletRequest request = (HttpServletRequest) req;
            HttpServletResponse response = (HttpServletResponse) res;
            HttpSession session = request.getSession(false);
    
            session.invalidate();
            String redirectUri = "/index.xhtml";
            if(request.getParameterMap().containsKey("redirect")) {
                    String[] vals = request.getParameterMap().get("redirect");
                    if(vals.length>0) {
                        redirectUri = vals[0];
                    }
            }
    
            Cookie[] userCookies = request.getCookies();
            if (userCookies != null && userCookies.length > 0 ) {
                for (int i = 0; i < userCookies.length; i++) {
                    if(userCookies[i].getName().equals("JSESSIONID")) {
                        Cookie jSessionId = userCookies[i];
                        jSessionId.setMaxAge(0);
                        response.addCookie(jSessionId);
                    }
                }
            }
    
                response.sendRedirect(redirectUri);
    
        }