BUG: possible busy loop when connection is closed while trying to establish SSL connection

From: Hannu Krosing <hannu(at)tm(dot)ee>
To: pgsql-hackers(at)postgresql(dot)org
Subject: BUG: possible busy loop when connection is closed while trying to establish SSL connection
Date: 2004-09-23 00:11:02
Message-ID: 1095898262.3552.5.camel@fuji.krosing.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Neil Conway 2004-09-23 00:30:45 Re: CVS configure failure
Previous Message Robert Treat 2004-09-22 17:19:09 Re: Variable assignment from dynamic SQL in PL/PgSQL