PQisBusy returns true but no more data is received. - Mailing list pgsql-general

From Pelle Johansson
Subject PQisBusy returns true but no more data is received.
Date
Msg-id 83326227-45CB-42B6-BCD6-2646E037FCAA@morth.org
Whole thread Raw
Responses Re: PQisBusy returns true but no more data is received.  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Hello list,

I'm new here, but didn't see the problem in the archives.

Basically, I have an epoll loop that executes the following code when
I receive data from postgresql (greatly simplified).

int read_sql (PGconn *conn)
{
   PGnotify *notice;
   PGresult *res;

   if (!PQconsumeInput (conn))
     return -1;

   while (1)
   {
     while ((notice = PQnotifies (conn)))
     {
       handle_notice (notice);
       PQmemfree (notice);
     }

     if (PQisBusy (conn))
       return 0;

     res = PQgetResult (conn);
     if (!res)
       break;

     while ((notice = PQnotifies (conn)))
     {
       handle_notice (notice);
       PQmemfree (notice);
     }

     handle_result (res);
     PQclear (res);
   }

   handle_query_done (conn);
}

(I've not tried to compile this sample code.)
The SQL query in question is a BEGIN followed by a SELECT (sent in
the same PQsendQuery()).

The problem is that after two iterations in the loop PQisBusy()
returns true, making me exit to the event loop, but no more data is
received, so the function will not be called again. If I disable the
call to PQisBusy() everything works as expected (PQgetResult() will
return NULL on the third iteration). If I move the call to PQisBusy()
outside the loop, everything also works good.

Is it safe to move the call to PQisBusy() outside the loop, or is it
possible that PQgetResult() will block on a long SELECT in that case?
(that would be very bad for me). Or have I misunderstood something
about these functions?
--
Pelle Johansson


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: How many postmasters should be running?
Next
From: Volkan YAZICI
Date:
Subject: Re: Breaking Path/Polygon Data into Pieces