BUG #1467: fe_connect doesn't handle EINTR right

Started by Florian Harsabout 21 years ago6 messageshackersbugs
Jump to latest
#1Florian Hars
hars@bik-gmbh.de
hackersbugs

The following bug has been logged online:

Bug reference: 1467
Logged by: Florian Hars
Email address: hars@bik-gmbh.de
PostgreSQL version: 8.0.1
Operating system: All
Description: fe_connect doesn't handle EINTR right
Details:

The file pgsql/src/interfaces/libpq/fe-connect.c contains the code fragment

retry_connect:
if (connect(conn->sock, addr_cur->ai_addr,
addr_cur->ai_addrlen) < 0)
{
if (SOCK_ERRNO == EINTR)
/* Interrupted system call - just try again */
goto retry_connect;
}

This is not in accordance with a strict legalistic reading of the POSIX
spec, according to which connect is not restartable so that you have to use
select or poll after connect returned with EINTR.

See
http://www.eleves.ens.fr:8080/home/madore/computers/connect-intr.html
for the ugly details, your code should work on Linux, but not on Solaris or
(Free|Open)BSD.

#2Bruce Momjian
bruce@momjian.us
In reply to: Florian Hars (#1)
hackersbugs
Re: [BUGS] BUG #1467: fe_connect doesn't handle EINTR right

Would someone comment on this bug report from February? I can confirm
the code is unchanged and is in function fe-connect.c::PQconnectPoll().

---------------------------------------------------------------------------

Florian Hars wrote:

The following bug has been logged online:

Bug reference: 1467
Logged by: Florian Hars
Email address: hars@bik-gmbh.de
PostgreSQL version: 8.0.1
Operating system: All
Description: fe_connect doesn't handle EINTR right
Details:

The file pgsql/src/interfaces/libpq/fe-connect.c contains the code fragment

retry_connect:
if (connect(conn->sock, addr_cur->ai_addr,
addr_cur->ai_addrlen) < 0)
{
if (SOCK_ERRNO == EINTR)
/* Interrupted system call - just try again */
goto retry_connect;
}

This is not in accordance with a strict legalistic reading of the POSIX
spec, according to which connect is not restartable so that you have to use
select or poll after connect returned with EINTR.

See
http://www.eleves.ens.fr:8080/home/madore/computers/connect-intr.html
for the ugly details, your code should work on Linux, but not on Solaris or
(Free|Open)BSD.

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#2)
hackersbugs
Re: [BUGS] BUG #1467: fe_connect doesn't handle EINTR right

Bruce Momjian <pgman@candle.pha.pa.us> writes:

Would someone comment on this bug report from February?

The report scored about zero out of zero IMHO: neither an actual report
of field trouble, nor a clear explanation of the supposed trouble, nor
a specific proposal what to do about it.

Without actual field trouble reports I am disinclined to touch the code
anyway ... chasing after unproven portability issues is an unprofitable
pursuit in my experience, since you can have no way to know if you've
actually fixed whatever real bug may exist.

regards, tom lane

#4Bruce Momjian
bruce@momjian.us
In reply to: Florian Hars (#1)
hackersbugs
Re: [BUGS] BUG #1467: fe_connect doesn't handle EINTR right

Though we have had no problem reports of this, there is confirmation
that our code is incorrect. Would someone develop a patch to fix this?

Thanks.

---------------------------------------------------------------------------

Florian Hars wrote:

The following bug has been logged online:

Bug reference: 1467
Logged by: Florian Hars
Email address: hars@bik-gmbh.de
PostgreSQL version: 8.0.1
Operating system: All
Description: fe_connect doesn't handle EINTR right
Details:

The file pgsql/src/interfaces/libpq/fe-connect.c contains the code fragment

retry_connect:
if (connect(conn->sock, addr_cur->ai_addr,
addr_cur->ai_addrlen) < 0)
{
if (SOCK_ERRNO == EINTR)
/* Interrupted system call - just try again */
goto retry_connect;
}

This is not in accordance with a strict legalistic reading of the POSIX
spec, according to which connect is not restartable so that you have to use
select or poll after connect returned with EINTR.

See
http://www.eleves.ens.fr:8080/home/madore/computers/connect-intr.html
for the ugly details, your code should work on Linux, but not on Solaris or
(Free|Open)BSD.

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#4)
hackersbugs
Re: [BUGS] BUG #1467: fe_connect doesn't handle EINTR right

Bruce Momjian <pgman@candle.pha.pa.us> writes:

Though we have had no problem reports of this, there is confirmation
that our code is incorrect. Would someone develop a patch to fix this?

s/there is confirmation/there is an entirely unsupported assertion/

I'd like to see an actual demonstration of trouble before we take
this seriously.

regards, tom lane

#6Bruce Momjian
bruce@momjian.us
In reply to: Florian Hars (#1)
hackersbugs
Re: BUG #1467: fe_connect doesn't handle EINTR right

I think this has been corrected in 8.1.

---------------------------------------------------------------------------

Florian Hars wrote:

The following bug has been logged online:

Bug reference: 1467
Logged by: Florian Hars
Email address: hars@bik-gmbh.de
PostgreSQL version: 8.0.1
Operating system: All
Description: fe_connect doesn't handle EINTR right
Details:

The file pgsql/src/interfaces/libpq/fe-connect.c contains the code fragment

retry_connect:
if (connect(conn->sock, addr_cur->ai_addr,
addr_cur->ai_addrlen) < 0)
{
if (SOCK_ERRNO == EINTR)
/* Interrupted system call - just try again */
goto retry_connect;
}

This is not in accordance with a strict legalistic reading of the POSIX
spec, according to which connect is not restartable so that you have to use
select or poll after connect returned with EINTR.

See
http://www.eleves.ens.fr:8080/home/madore/computers/connect-intr.html
for the ugly details, your code should work on Linux, but not on Solaris or
(Free|Open)BSD.

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073