I have multiple instances of socket.io with authentication running under HAProxy, and I need to force the authentication request and socket connection to go to the same instance. I configured HAProxy based on this answer to the SO question with some changes:
global maxconn 4096 # Total Max Connections. This is dependent on ulimit nbproc 2 defaults mode http frontend all 0.0.0.0:80 timeout client 86400000 default_backend www_backend acl is_websocket hdr(Upgrade) -i WebSocket acl is_websocket hdr_beg(Host) -i ws use_backend socket_backend if is_websocket backend www_backend balance url_param sessionId option forwardfor # This sets X-Forwarded-For timeout server 30000 timeout connect 4000 server server1 localhost:8081 weight 1 maxconn 1024 check server server2 localhost:8082 weight 1 maxconn 1024 check server server3 localhost:8083 weight 1 maxconn 1024 check backend socket_backend balance url_param sessionId option forwardfor # This sets X-Forwarded-For timeout queue 5000 timeout server 86400000 timeout connect 86400000 server server1 localhost:8081 weight 1 maxconn 1024 check server server2 localhost:8082 weight 1 maxconn 1024 check server server3 localhost:8083 weight 1 maxconn 1024 check
I tried url_param (where sessionId is the querystring parameter passed both during the authentication call and in connection with the web server) and the source as balance parameters, but it seems that HAProxy allows these options for HTTP connections and therefore ignores them for the actual network connection. As a result, sometimes auth request and socket connection end on different servers, which is unacceptable for our application.
Is there any way to get this desired behavior?
Diego Nov 16 2018-11-11T00: 00Z
source share