sql: sqlalchemy client using secure conn via haproxy loses conn periodically
BUG REPORT
- header of most recent log file
I180422 00:37:37.292611 1110 util/log/clog.go:1001 [config] file created at: 2018/04/22 00:37:37
I180422 00:37:37.292611 1110 util/log/clog.go:1001 [config] running on machine: db03
I180422 00:37:37.292611 1110 util/log/clog.go:1001 [config] binary: CockroachDB CCL v2.0.0 (x86_64-unknown-linux-gnu, built 2018/04/03 20:56:09, go1.10)
I180422 00:37:37.292611 1110 util/log/clog.go:1001 [config] arguments: [/usr/local/bin/cockroach start --certs-dir=/etc/cockroach/certs --store=/var/lib/storage/cockroach/data/ --http-host=0.0.0.0 --host=10.0.0.3 --join=10.0.0.2:26257 --cache=40% --max-sql-memory=40% --logtostderr=ERROR]
- Please describe the issue you observed:
-
What did you do? Started using haproxy to load balance 3 cockroach servers.
-
What did you expect to see? No errors.
-
What did you see instead? Periodic connection errors in client logs:
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) SSL SYSCALL error: EOF detected
When connecting directly to one of the 3 cockroach servers there are no errors, but when connecting through haproxy I'm seeing periodic connection errors. The haproxy config:
global
maxconn 4096
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
user haproxy
group haproxy
daemon
defaults
log global
option dontlognull
mode tcp
# Timeout values should be configured for your specific use.
# See: https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#4-timeout%20connect
timeout connect 10s
timeout client 1m
timeout server 1m
# TCP keep-alive on client side. Server already enables them.
option clitcpka
listen psql
bind :26257
mode tcp
balance roundrobin
option httpchk GET /health?ready=1
server cockroach1 10.0.0.2:26257 check port 8080
server cockroach2 10.0.0.3:26257 check port 8080
server cockroach3 10.0.0.4:26257 check port 8080
Even when I comment out cockroach2 and cockroach3 from haproxy.cfg so only one server is left, the connection errors still occur.
@mberhault do we have a test that uses haproxy with SSL enabled? I think we must have one, but I'm not sure where.
We don't, mostly because we use tcp-level load balancing in ha-proxy, so it doesn't matter much whether we're running insecure or secure. @alanhamlett: does your client remain idle for a while? If so, haproxy might be terminating the connection (see the timeouts in the config).
haproxy might be terminating the connection (see the timeouts in the config).
That was my first thought too, so I increased the haproxy timeout to a large number but it had no effect.
What happens if you set maxconn to 1 and have a single SQL client issue a SELECT 1 every, say, 5s?
That was my first thought too, so I increased the haproxy timeout to a large number but it had no effect.
You increased all of the timeouts, right?
Hi @alanhamlett - do you still need assistance here?
do you still need assistance here?
Yes, sorry for the late reply. It's hard to test since this is production data and I'm not able to have only one sql client connect to the cluster. I can try a new haproxy connected to the cluster with a single client issuing select every 5s to see if that reproduces it?
Hello @alanhamlett
Was wondering if you were still having these problems. Let me know how it's looking now, and if there are any other questions you may have.
Cheers, Ricardo
Was wondering if you were still having these problems.
I've switched to a Postgres + Archive to S3 design instead of Cockroach. I'll be sure to update if I use Cockroach again in the future.