SSL negotiation error on massive connect/disconnect

Started by Maxim Orlovover 5 years ago2 messageshackers
Jump to latest
#1Maxim Orlov
m.orlov@postgrespro.ru

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

Attachments:

0001-WIP.patchtext/x-diff; name=0001-WIP.patchDownload+147-2
#2Maxim Orlov
m.orlov@postgrespro.ru
In reply to: Maxim Orlov (#1)
Re: SSL negotiation error on massive connect/disconnect

On 2021-03-01 17:22, Maxim Orlov wrote:

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

Correction. Previous patch was wrong. The proper one is here.

---
Best regards,
Maxim Orlov.

Attachments:

t43773_2
0001-WIP-2.patchtext/x-diff; name=0001-WIP-2.patchDownload+151-1