Can HAProxy reconnect a websocket to another backend server transparently?

bdem asked:

I’m new to HAProxy so this might have an obvious answer but I wasn’t able to find it.

Consider this setup:

  • two backend web applications;
  • one HAProxy in front of the web applications;
  • many clients with websocket capable browsers;

A client opens a websocket connection to the HAProxy which chooses a web aplication by round robin, let’s say WebApp1 is chosen. The websocket connection stays on WebApp1 and is tunneled through the HAProxy.

If WebApp1 goes down, the client receives a disconnect, reconnects again, goes through the HAProxy which now selects WebApp2 and the websocket connection stays on WebApp2 tunneled through HAProxy.

That’s the normal setup, right?

What I want to ask if it’s possible for HAProxy to keep the websocket opened with the client and when WebApp1 goes down transparently move that end of the connection to WebApp2 without the client knowing about it. Is this possible?

My answer:

No, that’s not possible, because the new server knows nothing about the state of the previous connection. A WebSocket is not stateless like UDP or ØMQ. The client must reconnect in this case.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.