BUG: possible busy loop when connection is closed while trying to establish SSL connection - Mailing list pgsql-hackers

From Hannu Krosing
Subject BUG: possible busy loop when connection is closed while trying to establish SSL connection
Date
Msg-id 1095898262.3552.5.camel@fuji.krosing.net
Whole thread Raw
Responses Re: BUG: possible busy loop when connection is closed while trying to establish SSL connection  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
We were bitten by the following bug a few times, when our server tried
to reestablish connections under bad network conditions:


if connection is closed while trying to get response to SSL setup packet
(i.e. conn->status is CONNECTION_SSL_STARTUP), we get a busy loop, as
line 1035 in 8.0.0.beta2:
   if (pqWaitTimed(1, 0, conn, finish_time)  {

tells that there is data to read (returns 0) while actually it is error 
(POLLERR & POLLHUP) and not POLLIN returned from  poll() and 
   nread = recv(conn->sock, &SSLok, 1, 0);

on line 1449 sets nread to 0, as there is in fact nothing to read from a
closed socket
after that the check on line 1462:
   if (nread == 0)       /* caller failed to wait for data */       return PGRES_POLLING_READING;

resumes the busy loop

in all other places recv()'ing is done throught pqsecure_read, which
checks for such condition.


I'm not familiar enough with code to suggest a proper fix (and I
quickfix our app by disabling SSL (PGSSLMODE=disable) - the default was
prefer ;), but this may come back to haunt others

--------------
Hannu




pgsql-hackers by date:

Previous
From: Robert Treat
Date:
Subject: Re: Variable assignment from dynamic SQL in PL/PgSQL
Next
From: Neil Conway
Date:
Subject: Re: CVS configure failure