Re: nonblocking PQsendQuery will fail for querysize > 8k - Mailing list pgsql-interfaces

From Tom Lane
Subject Re: nonblocking PQsendQuery will fail for querysize > 8k
Date
Msg-id 2585.1049226314@sss.pgh.pa.us
Whole thread Raw
In response to nonblocking PQsendQuery will fail for querysize > 8k  (Andreas Pflug <Andreas.Pflug@web.de>)
List pgsql-interfaces
Andreas Pflug <Andreas.Pflug@web.de> writes:
> I'm having trouble with PQsendQuery if sending medium sized 
> queries. Everything's fine with queries up to 8190 bytes (0x1fffe), but one 
> byte more will not work.

libpq's nonblock mode is incredibly fragile, not to say completely
broken.  See discussion from, eg, Jan 2000:
http://archives.postgresql.org/pgsql-hackers/2000-01/msg00964.php
http://archives.postgresql.org/pgsql-hackers/2000-01/msg01048.php
and nearby comments.

AFAIK most of those complaints never did get addressed; so the nonblock
mode works under light load but falls over as soon as it's stressed at
all.  I'd like to see it rewritten properly, but have not had time
myself.

Making pqPutBytes willing to realloc the output buffer bigger would
definitely help, but it's not the only thing needed to make nonblock
mode robust, per comments in above messages.

BTW, reallocing just big enough to handle the current input is not the
way to go; that will result in lots of malloc traffic if the caller adds
a few bytes at a time.  I'd think about doubling the buffer size until
it's big enough.  Your proposed code is also nonrobust about running out
of memory.
        regards, tom lane



pgsql-interfaces by date:

Previous
From: Andreas Pflug
Date:
Subject: nonblocking PQsendQuery will fail for querysize > 8k
Next
From: Bruce Badger
Date:
Subject: The new FE/BE protocol