Re: libpq, threads and connection reset

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Joe Murphy <joe(dot)murphy(at)aersoft(dot)ie>
Cc: "pgsql-interfaces(at)postgresql(dot)org" <pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: libpq, threads and connection reset
Date: 2002-09-05 14:19:24
Message-ID: 29109.1031235564@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Joe Murphy <joe(dot)murphy(at)aersoft(dot)ie> writes:
>> The re-connect underlying call to connect returns -1 and errno = 0, so
>> it thinks the connection is "in progress" and tries
>> to complete the connection - but hangs on the select (poll)

Well, you have a bug in connect() if it's returning the wrong errno
in the multi-thread case.

However, our code in fe-connect.c reads like this:

if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) < 0)
{
if (SOCK_ERRNO == EINTR)
/* Interrupted system call - we'll just try again */
goto retry1;

if (SOCK_ERRNO == EINPROGRESS || SOCK_ERRNO == EWOULDBLOCK || SOCK_ERRNO == 0)
{
/*
* This is fine - we're in non-blocking mode, and the
* connection is in progress.
*/
conn->status = CONNECTION_STARTED;
}
else
{
/* Something's gone wrong */
connectFailureMessage(conn, SOCK_ERRNO);
goto connect_errReturn;
}

I wonder whether it's really a good idea to treat errno == 0 as
indicating "connection in progress". Does anyone know of a platform
where zero is actually what is returned in this case? The man pages
I can find all say that EINPROGRESS is returned.

regards, tom lane

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Iavor Raytchev 2002-09-06 07:21:57 Re: Setting up pgaccess on Win2k
Previous Message Joe Murphy 2002-09-05 12:54:59 Re: libpq, threads and connection reset