Hello!
I’ve written a minimal example which mimics my actual setup (where I originally observed this problem). The code for reproducing the issue: GitHub - inicula/haproxy-grpc-issue
server.go
is a gRPC server that listens on port 50052. It only has a unary method, which loops and prints the status of the context/connection (e.g. closed or not), until the context is closed.
client.go
is a gRPC client that connects to the server on 50052 directly, or via a HAProxy instance on 50053 when the --proxy
flag is given. The client just waits for 3 seconds, after which it cleanly closes the connection (the client will always have time to do this since the server loops until the connection is closed).
Now, my problem is that when I do:
go run server.go # in terminal 1
go run client.go # in terminal 2
After 3 seconds, the context/connection is correctly reported server-side as having been closed by the client. For my use-case, this is the expected behavior.
But when I use HAProxy, as follows:
cd haproxy # in terminal 1, fresh clone from latest master @ https://github.com/haproxy/haproxy.git
make -j4 TARGET=linux-glibc
./haproxy -f /path/to/haproxy.cfg # see https://github.com/inicula/haproxy-grpc-issue/blob/main/haproxy.cfg
go run server.go # in terminal 2
go run client.go --proxy # in terminal 3
Then, after 3 seconds pass, the gRPC client closes the connection, but the connection from the proxy to the server is kept alive (the context keeps being reported as open). For my usecase, this behavior is unexpected.
What I’m trying to do is make the HAProxy scenario behave the same as the no-HAProxy scenario. Meaning that when I close the client->proxy connection, I want the proxy->server connection to be closed too.
I’ve browsed through a few issues on github and it seems like option abortonclose
should grant me the behavior I’m looking for, but it doesn’t work. Either I don’t understand the option correctly, or the option doesn’t work as intended.
Would really appreciate some help figuring out the issue/answer here.
Thanks!