Skip site navigation (1) Skip section navigation (2)

PQsetdbLogin bug?

From: Tatsuo Ishii <t-ishii(at)sra(dot)co(dot)jp>
To: pgsql-hackers(at)postgresql(dot)org
Subject: PQsetdbLogin bug?
Date: 2001-05-25 13:12:39
Message-ID: 20010525221239F.t-ishii@sra.co.jp (view raw or flat)
Thread:
Lists: pgsql-hackers
Sometimes PQfinish() does not return forever in the following program.

conn = PQsetdbLogin();
if(PQstatus(conn) == CONNECTION_BAD)
{
  PQfinish(conn);	/* blocks here */
}

PQfinish calls closePGconn that call pqPuts. pqPuts calls select(2)
and it never returns if a connection associated with the socket is not
established.

This could happend if the connection is not established, but the
socket is still opened by PQsetdbLogin. Possible fixes are:

1) close the socket in PQsetdbLogin if it is in a situation being
   returns CONNECTION_BAD

		case PGRES_POLLING_WRITING:
			if (pqWait(0, 1, conn))
			{
				conn->status = CONNECTION_BAD;
				close(conn->sock); <-- add this
				conn->sock == -1;  <-- add this
				return 0;
			}
			break;


2) check if the status of handle returned PQsetdbLogin is
   CONNECTION_BAD closePGconn. if so, do not call pqPuts (and
   pqFlush)

   change this:
	if (conn->sock >= 0)

   to:
	if (conn->status != CONNECTION_BAD && conn->sock >= 0)

any thoughts?
--
Tatsuo Ishii



Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2001-05-25 13:47:26
Subject: Re: GiST index on data types that require compression
Previous:From: Matthew KirkwoodDate: 2001-05-25 09:21:01
Subject: Re: Re: Shared memory for RH Linux 7.1

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group