2

I am using haproxy 1.5.4 . in front of pgbouncer .

my configuration has pgsql-check enabled . Once the check is enabled i see these messages in pgbouncer log .

2015-10-01 05:02:46.203 27104 LOG C-0x6609d0: (nodb)/(nouser)@10.53.6.132:38711 closing because: client unexpected eof (age=8)
2015-10-01 05:02:58.205 27104 LOG C-0x6609d0: (nodb)/(nouser)@10.53.6.132:39111 closing because: client unexpected eof (age=8)
2015-10-01 05:03:10.207 27104 LOG C-0x6609d0: (nodb)/(nouser)@10.53.6.132:39707 closing because: client unexpected eof (age=9)
2015-10-01 05:03:22.208 27104 LOG C-0x6609d0: (nodb)/(nouser)@10.53.6.132:40281 closing because: client unexpected eof (age=8)

These were the same messages i was getting when the default check was there . I mean when there was no option pgsql-check.

I have also tried providing a valid user in the pgsql-check and still i see the eof message like this .

option pgsql-check user pg

2015-10-01 04:58:27.057 27104 LOG C-0x6609d0: pg/pg@10.53.6.132:17813 login attempt: db=pg user=pg
2015-10-01 04:58:27.057 27104 LOG C-0x6609d0: pg/pg@10.53.6.132:17813 closing because: client unexpected eof (age=0)
2015-10-01 04:58:29.058 27104 LOG C-0x6609d0: pg/pg@10.53.6.132:17882 login attempt: db=pg user=pg
2015-10-01 04:58:29.058 27104 LOG C-0x6609d0: pg/pg@10.53.6.132:17882 closing because: client unexpected eof (age=0)

My question is how different is pgsql-check from the the default tcp check . I was under impression that it will close the connection properly and i will not be seeing these message in the log .

Are we seeing these messages even with pgsql-check ?

arch
  • 1,363
  • 2
  • 14
  • 30
user101736
  • 21
  • 3

2 Answers2

2

I have the same kind of messages when HAProxy is connecting directly to PostgreSQL (in my case postgres 9.4 and HAProxy 1.5).

Without giving any username I get:

LOG:  could not receive data from client: Connection reset by peer
LOG:  incomplete startup packet

With a valid username:

LOG:  could not receive data from client: Connection reset by peer

So, apparently, pgsql-check without username seems to be pretty close to the "standard" tcp check. With the username it does seem to send a valid startup sequence. But in both case, the connection is terminated abruptly and not properly close or it seems.

The solution might be to use the generic TCP check to open and close the connection properly but that kind of defy the whole pgsql-check purpose.

ITChap
  • 4,057
  • 1
  • 21
  • 46
0

I made such a configuration with the generic TCP check. I can actually confirm that it's also receiving the same error in the logs.

You can find a python script + example configuration in my github repo https://github.com/gplv2/haproxy-postgresql

Even though I do send a proper hex close, I still get this in the logs:

LOG: could not receive data from client: Connection reset by peer

Afaik, I send a proper close, I've analysed this with wireshark multiple times to see what exactly a close sends to a PG database:

# write: terminate session
tcp-check send-binary 58                       # Termination packet
tcp-check send-binary 00000004                 # packet length: 4 (no body)

This is the hex dump of a quit (command line client test)

00000000 58 00 00 00 04 X....

Fact that the standard psql-check in haproxy as well as a custom made generic one seems to yield the same results is quite interesting. When I find the solution I will share it.

EDIT: adding source of psql protocol information: https://www.postgresql.org/docs/9.5/static/protocol-message-formats.html

afaik, I implemented the close exactly as documented to no avail.

Glenn Plas
  • 1,608
  • 15
  • 17