# Standalone-ha loosing session when switching backends to on/off

**URL:** <https://forum.keycloak.org/t/standalone-ha-loosing-session-when-switching-backends-to-on-off/12167>\
**Category:** Miscellanaeous\
**Tags:** clustering\
**Created:** [November 17, 2021, 7:36pm UTC](https://forum.keycloak.org/t/standalone-ha-loosing-session-when-switching-backends-to-on-off/12167 "2021-11-17T19:36:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ftbarata](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/ftbarata/32/4334_2.png) [@ftbarata](https://forum.keycloak.org/u/ftbarata)\
**Post date:** [November 17, 2021, 7:36pm UTC](https://forum.keycloak.org/t/standalone-ha-loosing-session-when-switching-backends-to-on-off/12167/1 "2021-11-17T19:36:30Z")

</div>

I’ve setup 2 standalone-ha virtual machines with a shared database and a http/https load balancer in front. If I log in with the 2 vm up and then power off one of them, when I refresh the page it takes me back to login page. So the session is not being preserved. What can I do to solve it?

---

<div class="post-metadata">

**Author:** ![mbonn](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/mbonn/32/5755_2.png) [@mbonn](https://forum.keycloak.org/u/mbonn)\
**Post date:** [November 18, 2021, 7:11am UTC](https://forum.keycloak.org/t/standalone-ha-loosing-session-when-switching-backends-to-on-off/12167/2 "2021-11-18T07:11:34Z")

</div>

Hi,

I’ve got a similar setup and I had to do the following to make infinispan to share the sessions:  
(1) in standalone-ha.xml, infinispan section, set owners=“2” (or higher value) on the entries. As I remember, the default value is “1”, which is useless.  
(2) add to the standalone startup script the parameters -bprivate={IP\_OF\_NODE\_X} -Djboss.node.name={NAME\_OD\_NODE\_X} -Djboss.tx.node.id={NAME\_OF\_NODE\_X} where X is the numer of your node…  
(3) in bin/standalone.conf set -Xmx2G (or higher), because infinispan tends to do no garbage collection on expired sessions (keycloak version 13.0.1)

I run an apache proxy in AJP-mode in front of each node. Both apaches are pointing to both keycloaks, havng an additional hardware load balancer (F5 BIG IP) in front of the apaches. In case of a keycloak maintenance (or VM reboot/crash…), users will not recognize the absence of the machine.

Bye, Matthias

---

<div class="post-metadata">

**Author:** ![dasniko](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/dasniko/32/2969_2.png) [@dasniko](https://forum.keycloak.org/u/dasniko)\
**Post date:** [November 18, 2021, 8:27am UTC](https://forum.keycloak.org/t/standalone-ha-loosing-session-when-switching-backends-to-on-off/12167/3 "2021-11-18T08:27:10Z")

</div>

This is the same question/thread from the OP he already started here: [How does each node know about each other in ha mode?](http://forum.keycloak.org/t/how-does-each-node-know-about-each-other-in-ha-mode/11959)

---

<div class="post-metadata">

**Author:** ![mbonn](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/mbonn/32/5755_2.png) [@mbonn](https://forum.keycloak.org/u/mbonn)\
**Post date:** [November 18, 2021, 10:35am UTC](https://forum.keycloak.org/t/standalone-ha-loosing-session-when-switching-backends-to-on-off/12167/4 "2021-11-18T10:35:37Z")

</div>

sorry, I read the other (older) question _after_ this one… why do users open different threads to the same question…

---

<div class="post-metadata">

**Author:** ![ftbarata](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/ftbarata/32/4334_2.png) [@ftbarata](https://forum.keycloak.org/u/ftbarata)\
**Post date:** [November 18, 2021, 8:08pm UTC](https://forum.keycloak.org/t/standalone-ha-loosing-session-when-switching-backends-to-on-off/12167/5 "2021-11-18T20:08:10Z")

</div>

THANK YOU SO MUCH. IT WORKED! It´s preserving the session!
