title: Socket.io behind HAProxy behind Google Cloud load balancer giving connection errors
body: <p>We are trying to configure our Socket.io socket servers behind HAProxy and over HAProxy we are using Google Cloud Load Balancer, so that HAProxy is not the single point of failure. As mentioned in this post by <a href="https://medium.com/google-cloud/highly-available-websockets-on-google-cloud-c74b35ee20bc#.o6xxj5br8" rel="nofollow noreferrer">https://medium.com/google-cloud/highly-available-websockets-on-google-cloud-c74b35ee20bc#.o6xxj5br8</a>. Also depicted in the picture below.</p>
  
  <p><a href="https://i.stack.imgur.com/p2L6E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/p2L6E.png" alt="enter image description here"></a></p>
  
  <p>At the Google cloud load balancer we are using TCP Load balancing with SSL Proxy with Proxy Protocol ON.</p>
  
  <p>The HAProxy is configured to use Cookies so that a client always connects to the same server. However since cookies might not be available on all our clients system, we decided to use load balancing algorithm as <code>source</code> in HAProxy. Here is the HAProxy configuration</p>
  
  <p>global
        log /dev/log    local0
        log /dev/log    local1 notice
        chroot /var/lib/haproxy
        stats socket /run/haproxy/admin.sock mode 660 level admin
        stats timeout 30s
        maxconn 16384
        tune.ssl.default-dh-param 2048
        user haproxy
        group haproxy
        daemon</p>
  
  <pre><code>  # Default SSL material locations
    ca-base /etc/ssl/certs
    crt-base /etc/ssl/private
  
    # Default ciphers to use on SSL-enabled listening sockets.
    # For more information, see ciphers(1SSL). This list is from:
    #  https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
    ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
    ssl-default-bind-options no-sslv3
  
  defaults
    mode http
    log global
    option httplog
    option  http-server-close
    option  dontlognull
    option  redispatch
    option  contstats
    retries 3
    backlog 10000
    timeout client          25s
    timeout connect          5s
    timeout server          25s
    timeout tunnel        3600s
    timeout http-keep-alive  1s
    timeout http-request    15s
    timeout queue           30s
    timeout tarpit          60s
    default-server inter 3s rise 2 fall 3
    option forwardfor
  
  
  frontend public
    bind *:443 ssl crt /etc/ssl/private/key.pem ca-file /etc/ssl/private/cert.crt accept-proxy
    maxconn 50000
    default_backend ws
  
  backend ws
    timeout check 5000
    option tcp-check
    option log-health-checks
    balance source
    cookie QUIZIZZ_WS_COOKIE insert indirect nocache
    server ws1 socket-server-1:4000 maxconn 4096 weight 10 check rise 1 fall 3 check cookie ws1 port 4000
    server ws2 socket-server-1:4001 maxconn 4096 weight 10 check rise 1 fall 3 check cookie ws2 port 4001
    server ws3 socket-server-2:4000 maxconn 4096 weight 10 check rise 1 fall 3 check cookie ws3 port 4000
    server ws4 socket-server-2:4001 maxconn 4096 weight 10 check rise 1 fall 3 check cookie ws4 port 4001
  </code></pre>
  
  <p>This is however giving connection errors on around 5% of our clients as compared to our old single server system. Any suggestions?</p>
  
  <p>Edit: Connection errors means that the client was not able to connect to the socket server and the socket.io client was throwing connection errors. </p>
  
  <p>Thanks in advance.</p>