2.8. Recommended Settings by Configuration
Depending on your production setup, leaving the defaults as they are can cause logins to be lost or unnecessary sessions to pile up in the data grid. Find your configuration in the table below and adjust the settings. Setting names follow the Valve attributes; the filter method uses the same names (except domain for the cookie domain).
| Configuration | Setting | Reason |
|---|---|---|
| There are flows that return from another site with a form POST, such as payment, identity verification, or SSO | On HTTPS, set sameSite="None" together with secure="true" | See "POST Returning From Another Site" below |
| HTTPS ends at an L4 device or web server and Tomcat receives http | Set secure="true" yourself | The cookie Secure option follows only the setting. It is not turned on from the X-Forwarded-Proto header passed by the front device or from Tomcat's RemoteIpValve |
You use sessionDomain and there is a front proxy | Make the proxy pass the original Host (Apache ProxyPreserveHost On, nginx proxy_set_header Host $host) | The cookie Domain is added only when the request Host belongs to that domain |
| An L4 VIP sits in front of the data grid and the firewall opens only the VIP | infinispan.client.hotrod.client_intelligence = BASIC in hotrod.properties | See "When the Firewall Opens Only the Front Address (VIP)" in 2.7 |
| L4 or Kubernetes health checks call an application address | Add the health check path to excludeRegExp | See "Excluding Health Check Requests" below |
POST Returning From Another Site
Some flows, such as payment, identity verification, and SSO login, send the user to another site and bring them back with a form POST. If the browser does not send the session cookie at that point, the returning user's login is lost.
If SameSite (a cookie option that sends the cookie only on requests from the same site) is not set, Chrome treats it as Lax. Chrome then does not send the cookie on a POST returning from another site once two minutes have passed since the cookie was received. With sameSite="Lax", it is not sent even if the user returns right away.
If you have such flows, configure as follows. Browsers accept None only together with Secure over HTTPS.
<Valve className="io.openmaru.cluster.valve.InfinispanHotRodSessionValve"
...
sameSite="None"
secure="true"/>
If there are no such flows, leave sameSite unset or set it to Lax.
The examples in this chapter use the class name for Tomcat 8.5 and 9. For Tomcat 10 and later, use io.openmaru.cluster.jakarta.valve.InfinispanHotRodSessionValve. With the servlet filter method, set the same names as init-params.
Excluding Health Check Requests
When an L4 switch or Kubernetes sends health checks to an application address, each request has no cookie, so every request creates a new session in the data grid, which remains for sessionTimeout. A thousand health checks leave a thousand sessions.
Adding the health check path to excludeRegExp prevents sessions from being created. Join it to the static file pattern with |.
<Valve className="io.openmaru.cluster.valve.InfinispanHotRodSessionValve"
...
excludeRegExp="/health.*|/.+\.(html|jpg|jpeg|png|gif|js|css|swf|ico|svg|webp|woff|woff2|ttf|eot|otf)"/>
excludeRegExp is compared against the whole request address, including the context path. If the application is at /myapp, write /myapp/health.*.
Data Grid Startup Order and Behavior During Outages
Start the data grid (Infinispan) before Tomcat.
If Tomcat starts while the data grid is down, session management cannot start and the application does not come up. Failed to initialize Infinispan HotRod Session Store is logged and pages return 404. In this state the application does not recover on its own even if the data grid is started later. Recover in this order.
- Start the data grid servers.
- Confirm that the data grid is reachable.
- Restart Tomcat, or reload the application.
If the data grid goes down during operation, a connection error is logged for every request, so log files grow quickly. Check the free space on the log disk and the log rotation settings in advance. When the data grid comes back, the connection is restored automatically.
Run the Data Grid on Two or More Servers
In production, run the data grid on two or more servers and have the session cache keep two copies of each session (owners=2 in the Infinispan cache configuration). For the number of servers, see "How Many Data Grid Nodes to Deploy" in Part 1.
If a single data grid server stores sessions only in memory, all sessions are lost when that server restarts, and every user has to log in again.
Caution Even with two or more servers, at the moment one data grid server leaves (a few seconds), some sessions of requests in progress may be reset, and those users may need to log in again. The other sessions are kept. If you need to take a data grid server down for maintenance, do it one server at a time when traffic is low.