SSL negotiation error on massive connect/disconnect

From: Maxim Orlov <m(dot)orlov(at)postgrespro(dot)ru>
To: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: SSL negotiation error on massive connect/disconnect
Date: 2021-03-01 14:22:27
Message-ID: b7591e867d123f7dbfa2d4b53bb6618c@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi!

I have primary server on port 55942 and two standbys on 55943 and 55944.
Then use connection string like
"postgresql://127.0.0.1:55942,127.0.0.1:55943,127.0.0.1:55944/postgres"
to connect to the servers via psql.

Everything works perfectly no matter how many attempts to connect I do.
But when I stop primary server, very rarely I do get an error "received
invalid response to SSL negotiation" from psql. I got this error when I
tried to make massive connects/disconnects test and it's unlikely to
reproduce manually without thousands of connections sequentially with no
intentional delay in between.

The problem present only on Linux, MacOS works fine.

As far as I understand this particular problem is because of postgresql
gets "zero" (i.e. 0) byte in SSLok in
PQconnectPoll(at)src/interfaces/libpq/fe-connect.c. This lead to select
"else" branch with described error message. This may be fixed by
handling zero byte as 'E' byte. But I'm not sure if it's good solution,
since I don't know why fe-connect gets an zero byte at all.

I consider it's worth to correct this. This error is rare but it's
really odd to notice this unexpected and wrong behavior.

---
Best regards,
Maxim Orlov.

Attachment Content-Type Size
0001-WIP.patch text/x-diff 5.2 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2021-03-01 14:31:43 Re: Improvements in prepared statements
Previous Message Alejandro Sánchez 2021-03-01 14:20:31 Improvements in prepared statements