cockroach icon indicating copy to clipboard operation
cockroach copied to clipboard

sql: sqlalchemy client using secure conn via haproxy loses conn periodically

Open alanhamlett opened this issue 8 years ago • 8 comments

BUG REPORT

  1. 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]
  1. 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.

alanhamlett avatar Apr 22 '18 01:04 alanhamlett

@mberhault do we have a test that uses haproxy with SSL enabled? I think we must have one, but I'm not sure where.

tbg avatar May 03 '18 12:05 tbg

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).

mberhault avatar May 03 '18 13:05 mberhault

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.

alanhamlett avatar May 03 '18 13:05 alanhamlett

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?

tbg avatar May 05 '18 03:05 tbg

Hi @alanhamlett - do you still need assistance here?

tim-o avatar Jul 10 '18 18:07 tim-o

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?

alanhamlett avatar Jul 10 '18 19:07 alanhamlett

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

ricardocrdb avatar Jun 06 '19 17:06 ricardocrdb

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.

alanhamlett avatar Jun 11 '19 00:06 alanhamlett