Change sticky session cookie when backend changes

I have sticky session configured with cookie JSESSIONID prefix and option redispatch. A client loads a page, gets the prefix appended to JSESSIONID and some time later the backend dies. I expected the prefix to change to ensure that the client sticks to a new backend but the cookie isn’t changed. How can I configure the cookie to change and the client to stick to a new backend?

I have to use the prefix form of the cookie and HAProxy version is 2.1.4.

If the backend goes down, the JSESSIONID prefix should change. Have you configured the required checks so that HAProxy knows that the backend is down? Also, please provide the complete configuration as well as the logs in order to debug the issue.

Config:

backend inst25us-pool-secure
        option httpchk OPTIONS * HTTP/1.1\r\nHost:\ inst25us.mycompany.com
        balance roundrobin
	    server tomcat1251-s 192.168.1.118:12510 cookie inst25us-app04-1251 check
		server tomcat2251-s 192.168.1.160:22510 cookie inst25us-app05-2251 check
		server tomcat3251-s 192.168.1.10:32510 cookie inst25us-app06-3251 check
        option redispatch
        cookie JSESSIONID prefix 
        stats uri /amit-status/
        option forwardfor except 127.0.0.1 header X-Cluster-Client-IP
        http-request add-header X-MYCOMPANY-HTTPS  1

Log (I killed the server at 02:51:57):

Jun 25 02:51:28 lb03 haproxy[6735]: 80.74.107.98:53613 [25/Jun/2020:02:51:28.794] inst25us-secure~ inst25us-pool-secure/tomcat1251-s 0/0/0/3/4 200 37116 - - --VN 27/25/0/0/0 0/0 {liran25.mycompany.com} "GET https://ohyeah.mycompany.com/favicon.ico HTTP/2.0"
Jun 25 02:51:33 lb03 haproxy[6735]: 80.74.107.98:51007 [25/Jun/2020:02:51:33.434] inst25us-secure~ inst25us-pool-secure/tomcat1251-s 0/0/1/15/16 200 595 - - --NR 27/25/0/0/0 0/0 {inst25us.mycompany.com} "GET /hello.jsp HTTP/1.1"
Jun 25 02:51:42 lb03 haproxy[6735]: 80.74.107.98:50284 [25/Jun/2020:02:51:42.732] inst25us-secure~ inst25us-pool-secure/tomcat1251-s 0/0/0/14/14 200 292 - - --NN 27/25/0/0/0 0/0 {autob28inst251753.mycompany.com} "GET /rdsKeepAlive?accountId=autob28inst251753&rdsName=AutoRDS909&rdsIp=10.14.1.134 HTTP/1.1"
Jun 25 02:51:57 lb03 haproxy[6735]: 80.74.107.98:51060 [25/Jun/2020:02:51:57.262] inst25us-secure~ inst25us-pool-secure/tomcat1251-s 0/0/0/16/16 200 595 - - --NR 19/18/0/0/0 0/0 {inst25us.mycompany.com} "GET /hello.jsp HTTP/1.1"
Jun 25 02:52:03 lb03 haproxy[6735]: 80.74.107.98:51060 [25/Jun/2020:02:52:03.428] inst25us-secure~ inst25us-pool-secure/tomcat3251-s 0/1/0/209/210 200 595 - - --NR 25/23/0/0/+1 0/0 {inst25us.mycompany.com} "GET /hello.jsp HTTP/1.1"
Jun 25 02:52:14 lb03 haproxy[6735]: 80.74.107.98:53648 [25/Jun/2020:02:52:09.808] inst25us-secure~ inst25us-pool-secure/tomcat3251-s 0/2002/1/2531/4534 200 15148 - - --DN 26/24/0/0/+3 0/0 {liran25.mycompany.com} "GET https://ohyeah.mycompany.com/Login.jsp?navLanguage=en-US HTTP/2.0"
Jun 25 02:52:28 lb03 haproxy[6735]: 80.74.107.98:51113 [25/Jun/2020:02:52:28.471] inst25us-secure~ inst25us-pool-secure/tomcat3251-s 0/0/0/18/18 200 595 - - --NR 25/24/0/0/0 0/0 {inst25us.mycompany.com} "GET /hello.jsp HTTP/1.1"
Jun 25 02:52:33 lb03 haproxy[6735]: 80.74.107.98:51113 [25/Jun/2020:02:52:33.436] inst25us-secure~ inst25us-pool-secure/tomcat3251-s 0/0/0/20/20 200 595 - - --NR 26/24/0/0/0 0/0 {inst25us.mycompany.com} "GET /hello.jsp HTTP/1.1"
Jun 25 02:52:59 lb03 haproxy[6735]: 80.74.107.98:51166 [25/Jun/2020:02:52:59.750] inst25us-secure~ inst25us-pool-secure/tomcat3251-s 0/0/0/19/19 200 595 - - --NR 24/23/0/0/0 0/0 {inst25us.mycompany.com} "GET /hello.jsp HTTP/1.1"