Re: libpq support for NegotiateProtocolVersion

From: Jacob Champion <jchampion(at)timescale(dot)com>
To: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>, Nathan Bossart <nathandbossart(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: libpq support for NegotiateProtocolVersion
Date: 2022-11-14 18:11:59
Message-ID: 4e3b63cb-07f5-5893-13fb-a5af805941dd@timescale.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 11/13/22 01:21, Peter Eisentraut wrote:
> On 11.11.22 23:28, Jacob Champion wrote:
>> Put another way, why do we loop around and poll for more data when we
>> hit the end of the connection buffer, if we've already checked at this
>> point that we should have the entire message buffered locally?
>
> Isn't that the same behavior for other message types? I don't see
> anything in the handling of the early 'E' and 'R' messages that would
> handle this.

I agree for the 'E' case. For 'R', I see the msgLength being passed down
to pg_fe_sendauth().

> If we want to address this, maybe this should be handled
> in the polling loop before we pass off the input buffer to the
> per-message-type handlers.

I thought it was supposed to be handled by this code:

> /*
> * Can't process if message body isn't all here yet.
> */
> msgLength -= 4;
> avail = conn->inEnd - conn->inCursor;
> if (avail < msgLength)
> {
> /*
> * Before returning, try to enlarge the input buffer if
> * needed to hold the whole message; see notes in
> * pqParseInput3.
> */
> if (pqCheckInBufferSpace(conn->inCursor + (size_t) msgLength,
> conn))
> goto error_return;
> /* We'll come back when there is more data */
> return PGRES_POLLING_READING;
> }

But after this block, we still treat EOF as if we need to get more data.
If we know that the message was supposed to be fully buffered, can we
just avoid the return to the pooling loop altogether and error out
whenever we see EOF?

Thanks,
--Jacob

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message samay sharma 2022-11-14 18:41:21 Re: Documentation for building with meson
Previous Message Aleksander Alekseev 2022-11-14 18:07:52 Re: Add 64-bit XIDs into PostgreSQL 15