3

I have HAProxy acting as a proxy in front of:

  • An NGinx instance
  • An in-house load balancer in front of multiple dynamic services exposed with socket.io (websockets)

My problem is that from time to time my connections are proxied correctly to my socket.io cluster, and then randomly it fallsback to routing to NGinx which obviously is annoying and meaningless since NGinx isn't mean't to handle the request.

This happens when requesting for URLs of the format :

http://mydomain.com/backends/*

There's an ACL in the HAProxy config to match the '/backends/*' path.

Here's a simplified version of my HAProxy config (removed extra unrelated entries and changed names):

global
    daemon
    maxconn 4096
    user haproxy
    group haproxy
    nbproc 4 

defaults
    mode http
    timeout server 86400000
    timeout connect 5000
    log global


#this frontend interface receives the incoming http requests
frontend http-in
    mode http

    #process all requests made on port 80
    bind *:80

    #set a large timeout for websockets
    timeout client 86400000

    # Default Backend
    default_backend www_backend

    # Loadfire (socket cluster)
    acl is_loadfire_backends path_beg /backends
    use_backend loadfire_backend if is_loadfire_backends


# NGinx backend
backend www_backend
    server www_nginx localhost:12346 maxconn 1024


# Loadfire backend
backend loadfire_backend
    option forwardfor # This sets X-Forwarded-For
    option httpclose
    server loadfire localhost:7101 maxconn 2048

It's really quite confusing for me why the behaviour appears to be "random", since being hard to reproduce it's hard to debug.

I appreciate any insight on this.

Nick
  • 256
  • 1
  • 5
  • 20
AaronO
  • 131
  • 5

1 Answers1

0

The problem was caused by the fact that when multiple HTTP requests are carried over the same TCP connection, the first request goes through the acl matching process and context switching to get a backend, but that does not hold for the following connections.

So to fix the problem, one should either one of the following in their frontend section :

option httpclose

or

option http-server-close

The above worked for me (I choosed the latter, http-server-close).

I found this documentation entry to be very useful: HAProxy documentation on Google Docs for http-close-server (the other entries are useful too).

AaronO
  • 131
  • 5