Обсуждение: Using PQexecQuery in pipeline mode produces unexpected Close messages

Поиск
Список
Период
Сортировка

Using PQexecQuery in pipeline mode produces unexpected Close messages

От
Daniele Varrazzo
Дата:
Hello,

Experimenting with pipeline mode, with libpq 14.2, sometimes we
receive the notice "message type 0x33 arrived from server while idle".
Tested with Postgres server 12 and 14.

This notice is generated by libpq upon receiving messages after using
PQsendQuery(). The libpq trace shows:

    F    101    Parse     "" "INSERT INTO pq_pipeline_demo(itemno,
int8filler) VALUES (1, 4611686018427387904) RETURNING id" 0
    F    12    Bind     "" "" 0 0 0
    F    6    Describe     P ""
    F    9    Execute     "" 0
    F    6    Close     P ""
    F    4    Flush
    B    4    ParseComplete
    B    4    BindComplete
    B    27    RowDescription     1 "id" 561056 1 23 4 -1 0
    B    11    DataRow     1 1 '3'
    B    15    CommandComplete     "INSERT 0 1"
    B    4    CloseComplete
    F    4    Sync
    B    5    ReadyForQuery     I

in the state the server messages are received, CloseComplete is unexpected.

For comparison, PQsendQueryParams() produces the trace:

    F    93    Parse     "" "INSERT INTO pq_pipeline_demo(itemno,
int8filler) VALUES ($1, $2) RETURNING id" 2 21 20
    F    36    Bind     "" "" 2 1 1 2 2 '\x00\x01' 8
'@\x00\x00\x00\x00\x00\x00\x00' 1 0
    F    6    Describe     P ""
    F    9    Execute     "" 0
    F    4    Flush
    B    4    ParseComplete
    B    4    BindComplete
    B    27    RowDescription     1 "id" 561056 1 23 4 -1 0
    B    11    DataRow     1 1 '4'
    B    15    CommandComplete     "INSERT 0 1"
    F    4    Sync
    B    5    ReadyForQuery     I

where no Close is sent.

Is this a problem with PQexecQuery which should not send the Close, or
with receiving in IDLE mode which should expect a CloseComplete?

Should we avoid using PQexecQuery in pipeline mode altogether?

A playground to reproduce the issue is available at
https://github.com/psycopg/psycopg/issues/314

Cheers

-- Daniele



Re: Using PQexecQuery in pipeline mode produces unexpected Close messages

От
Alvaro Herrera
Дата:
On 2022-Jun-08, Daniele Varrazzo wrote:

> Is this a problem with PQexecQuery which should not send the Close, or
> with receiving in IDLE mode which should expect a CloseComplete?

Interesting.

What that Close message is doing is closing the unnamed portal, which
is otherwise closed implicitly when the next one is opened.  That's how
single-query mode works: if you run a single portal, it'll be kept open.

I believe that the right fix is to not send that Close message in
PQsendQuery.

-- 
Álvaro Herrera               48°01'N 7°57'E  —  https://www.EnterpriseDB.com/
"Para tener más hay que desear menos"