# Change sticky session cookie when backend changes

**URL:** <https://discourse.haproxy.org/t/change-sticky-session-cookie-when-backend-changes/5382>\
**Category:** Help!\
**Created:** [June 24, 2020, 12:14pm UTC](https://discourse.haproxy.org/t/change-sticky-session-cookie-when-backend-changes/5382 "2020-06-24T12:14:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnny](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@johnny](https://discourse.haproxy.org/u/johnny)\
**Post date:** [June 24, 2020, 12:14pm UTC](https://discourse.haproxy.org/t/change-sticky-session-cookie-when-backend-changes/5382/1 "2020-06-24T12:14:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![void\_in](https://avatars.discourse-cdn.com/v4/letter/v/3ec8ea/32.png) [@void\_in](https://discourse.haproxy.org/u/void_in)\
**Post date:** [June 24, 2020, 5:35pm UTC](https://discourse.haproxy.org/t/change-sticky-session-cookie-when-backend-changes/5382/2 "2020-06-24T17:35:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![johnny](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@johnny](https://discourse.haproxy.org/u/johnny)\
**Post date:** [June 25, 2020, 7:10am UTC](https://discourse.haproxy.org/t/change-sticky-session-cookie-when-backend-changes/5382/3 "2020-06-25T07:10:13Z")

</div>

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"
```
