# Sticky session with Tomcat jvmroute

**URL:** <https://community.traefik.io/t/sticky-session-with-tomcat-jvmroute/12060>\
**Category:** Traefik v2\
**Tags:** docker-swarm, docker\
**Created:** [October 11, 2021, 3:07am UTC](https://community.traefik.io/t/sticky-session-with-tomcat-jvmroute/12060 "2021-10-11T03:07:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![groliveira18](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/groliveira18/32/4375_2.png) [@groliveira18](https://community.traefik.io/u/groliveira18)\
**Post date:** [October 11, 2021, 3:07am UTC](https://community.traefik.io/t/sticky-session-with-tomcat-jvmroute/12060/1 "2021-10-11T03:07:29Z")

</div>

Guys, I'm having a hard time implementing a Load Balancer Traefik V2 with serving as a proxy for Tomcat with sticky session.

Currently my application already works partially with the following settings:

```auto
        - traefik.enable=true
        - traefik.http.routers.tomcat.rule=Host(`app.exemple.com`) && PathPrefix(`/mypath/`)
        - traefik.http.services.tomcat.loadbalancer.server.port=8080
        - traefik.http.routers.tomcat.service=tomcat
        - traefik.http.routers.tomcat.entrypoints=web
        - traefik.http.services.tomcat.loadbalancer.sticky=true
        - traefik.http.services.tomcat.loadbalancer.sticky.cookie.name=StickyCookie

```

From then on I can't access my application, and from then on new problems arise.

My application is not configured to lose the session when refreshing the page and whenever I do this the session is destroyed using Traefik's LB.

My second problem is that some of my requests end up going to other containers in the cluster and this prevents me from running some tasks in the application, especially those that I consult an external service.

Ex: I use an external service to generate reports and the request for this service within the application is changed container and I cannot generate the report.

See that my access container is "[http://10.0.6.90:8080](http://10.0.6.90:8080)"

```auto
[t29s5](http://172.23.0.31:888/#/tasks/t29s530zs8m3uk5bx7benvlcv?log=1) 10.0.0.2 - - [11/Oct/2021:02:54:02 +0000] "POST /webrun/executeRule.do HTTP/1.1" 200 63 "-" "-" 795 "tomcat@docker" "http://10.0.6.90:8080" 31ms

```

nd now he walks between two different containers. "[http://10.0.6.101:8080](http://10.0.6.101:8080)" and "[http://10.0.6.97:8080](http://10.0.6.97:8080)" thus having error 500 Internal Server Error

```auto
[t29s5](http://172.23.0.31:888/#/tasks/t29s530zs8m3uk5bx7benvlcv?log=1) 10.0.0.2 - - [11/Oct/2021:02:55:28 +0000] "GET /webrun/download?id=A60E20F2-64D7-454E-8FB3-F95275A7EB9E&hash=911119621632346077000&name=PM_Juazeiro&jsessionid=F8BA71714A6BDB1C0C0C8A7E72D584D5 HTTP/1.0" 500 383 "-" "-" 811 "tomcat@docker" "http://10.0.6.101:8080" 12ms

[t7znc](http://172.23.0.31:888/#/tasks/t7znc4l1x2ynamx7f5uqqpde9?log=1) 10.0.0.2 - - [11/Oct/2021:02:55:29 +0000] "GET /webrun/download?id=A60E20F2-64D7-454E-8FB3-F95275A7EB9E&hash=911119621632346077000&name=PM_Juazeiro&jsessionid=F8BA71714A6BDB1C0C0C8A7E72D584D5 HTTP/1.0" 500 383 "-" "-" 633 "tomcat@docker" "http://10.0.6.97:8080" 2406ms

```

In other providers like Apache2 and NGINX I can work this normally, however I use Tomcat's jvmRoute. So I'm in doubt if there would be this possibility of Traefik or if there would be another solution to my problem.

Greetings from Brazil!!

---

<div class="post-metadata">

**Author:** ![groliveira18](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/groliveira18/32/4375_2.png) [@groliveira18](https://community.traefik.io/u/groliveira18)\
**Post date:** [October 13, 2021, 1:29pm UTC](https://community.traefik.io/t/sticky-session-with-tomcat-jvmroute/12060/2 "2021-10-13T13:29:32Z")

</div>

Guys, I ended up opening a problem on github too, if you want to follow up.

> <https://github.com/traefik/traefik/issues/8517>
>
> \### Welcome!
> 
> \- \[X\] Yes, I've searched similar issues on \[GitHub\](https://github….com/traefik/traefik/issues) and didn't find any.
> \- \[X\] Yes, I've searched similar issues on the \[Traefik community forum\](https://community.containo.us) and didn't find any.
> 
> \### What did you do?
> 
> Guys, I'm having a hard time implementing a Load Balancer Traefik V2 with serving as a proxy for Tomcat with sticky session.
> 
> Currently my application already works partially with the following settings:
> \`\`\`
> - traefik.enable=true
> - traefik.http.routers.tomcat.rule=Host(\`app.exemple.com\`) && PathPrefix(\`/mypath/\`)
> - traefik.http.services.tomcat.loadbalancer.server.port=8080
> - traefik.http.routers.tomcat.service=tomcat
> - traefik.http.routers.tomcat.entrypoints=web
> - traefik.http.services.tomcat.loadbalancer.sticky=true
> - traefik.http.services.tomcat.loadbalancer.sticky.cookie.name=StickyCookie
> \`\`\`
> 
> From then on I can't access my application, and from then on new problems arise.
> 
> My application is not configured to lose the session when refreshing the page and whenever I do this the session is destroyed using Traefik's LB.
> 
> My second problem is that some of my requests end up going to other containers in the cluster and this prevents me from running some tasks in the application, especially those that I consult an external service.
> 
> Ex: I use an external service to generate reports and the request for this service within the application is changed container and I cannot generate the report.
> 
> See that my access container is \*\*"http://10.0.6.90:8080"\*\*
> 
> \`\[t29s5 \](http://172.23.0.31:888/#/tasks/t29s530zs8m3uk5bx7benvlcv?log=1) 10.0.0.2 - - \[11/Oct/2021:02:54:02 +0000\] "POST /webrun/executeRule.do HTTP/1.1" 200 63 "-" "-" 795 "tomcat@docker" \*\*"http://10.0.6.90:8080"\*\* 31ms\`
> 
> and now he walks between two different containers. "http://10.0.6.101:8080" and "http://10.0.6.97:8080" thus having error 500 Internal Server Error
> 
> \### What did you see instead?
> 
> \`\[t29s5 \](http://172.23.0.31:888/#/tasks/t29s530zs8m3uk5bx7benvlcv?log=1) 10.0.0.2 - - \[11/Oct/2021:02:55:28 +0000\] "GET /webrun/download?id=A60E20F2-64D7-454E-8FB3-F95275A7EB9E&hash=911119621632346077000&name=PM\_Juazeiro&jsessionid=F8BA71714A6BDB1C0C0C8A7E72D584D5 HTTP/1.0" 500 383 "-" "-" 811 "tomcat@docker" \*\*"http://10.0.6.101:8080"\*\* 12ms\`
> 
> \`\[t7znc \](http://172.23.0.31:888/#/tasks/t7znc4l1x2ynamx7f5uqqpde9?log=1) 10.0.0.2 - - \[11/Oct/2021:02:55:29 +0000\] "GET /webrun/download?id=A60E20F2-64D7-454E-8FB3-F95275A7EB9E&hash=911119621632346077000&name=PM\_Juazeiro&jsessionid=F8BA71714A6BDB1C0C0C8A7E72D584D5 HTTP/1.0" 500 383 "-" "-" 633 "tomcat@docker" \*\*"http://10.0.6.97:8080"\*\* 2406ms\`
> 
> In other providers like Apache2 and NGINX I can work this normally, however I use Tomcat's jvmRoute. So I'm in doubt if there would be this possibility of Traefik or if there would be another solution to my problem.
> 
> Greetings from Brazil!!
> 
> \### What version of Traefik are you using?
> 
> Version: 2.5.3
> Codename: livarot
> Go version: go1.17.1
> Built: 2021-09-20T15:43:56Z
> OS/Arch: linux/amd64
> 
> 
> \### What is your environment & configuration?
> 
> \`\`\`
> - traefik.enable=true
> - traefik.http.routers.tomcat.rule=Host(\`app.exemple.com\`) && PathPrefix(\`/mypath/\`)
> - traefik.http.services.tomcat.loadbalancer.server.port=8080
> - traefik.http.routers.tomcat.service=tomcat
> - traefik.http.routers.tomcat.entrypoints=web
> - traefik.http.services.tomcat.loadbalancer.sticky=true
> - traefik.http.services.tomcat.loadbalancer.sticky.cookie.name=StickyCookie
> \`\`\`
> 
> \### If applicable, please paste the log output in DEBUG level
> 
> \_No response\_

---

<div class="post-metadata">

**Author:** ![groliveira18](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/groliveira18/32/4375_2.png) [@groliveira18](https://community.traefik.io/u/groliveira18)\
**Post date:** [October 19, 2021, 8:26pm UTC](https://community.traefik.io/t/sticky-session-with-tomcat-jvmroute/12060/3 "2021-10-19T20:26:26Z")

</div>

> [@groliveira18](#):
>
> `/webrun/download?...`

Guys, I could see that whenever I call a download within my context, the traefik is lost.

As I use sticky sessions this download is never called by the same container where the client is connected and I see no reason for traefik to do this.

Everything works very normal except when I need to download any file.
