Re: Using PQexecQuery in pipeline mode produces unexpected Close messages

From: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
To: tgl(at)sss(dot)pgh(dot)pa(dot)us
Cc: alvherre(at)alvh(dot)no-ip(dot)org, daniele(dot)varrazzo(at)gmail(dot)com, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Using PQexecQuery in pipeline mode produces unexpected Close messages
Date: 2022-06-16 03:07:47
Message-ID: 20220616.120747.1289213836703016883.horikyota.ntt@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

At Thu, 16 Jun 2022 10:34:22 +0900 (JST), Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com> wrote in
> PQgetResult() resets the state to IDLE while in pipeline mode.
>
> fe-exec.c:2171
>
> > if (conn->pipelineStatus != PQ_PIPELINE_OFF)
> > {
> > /*
> > * We're about to send the results of the current query. Set
> > * us idle now, and ...
> > */
> > conn->asyncStatus = PGASYNC_IDLE;
>
> And actually that code let the connection state enter to IDLE before
> CloseComplete. In the test case I posted, the following happens.
>
> PQsendQuery(conn, "SELECT 1;");
> PQsendFlushRequest(conn);
> PQgetResult(conn); // state enters IDLE, reads down to <CommandComplete>
> PQgetResult(conn); // reads <CloseComplete comes>
> PQpipelineSync(conn); // sync too late
>
> Pipeline feature seems intending to allow PQgetResult called before
> PQpipelineSync. And also seems allowing to call QPpipelineSync() after
> PQgetResult().
>
> I haven't come up with a valid *fix* of this flow..

The attached is a crude patch to separate the state for PIPELINE-IDLE
from PGASYNC_IDLE. I haven't found a better way..

regards.

--
Kyotaro Horiguchi
NTT Open Source Software Center

Attachment Content-Type Size
libpqpline-test.diff text/x-patch 3.3 KB
libpqpline-separte-pipelineidle-state.diff text/x-patch 4.4 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Noah Misch 2022-06-16 05:42:18 Re: Extension pg_trgm, permissions and pg_dump order
Previous Message Kyotaro Horiguchi 2022-06-16 01:41:21 Re: Using PQexecQuery in pipeline mode produces unexpected Close messages

Browse pgsql-hackers by date

  From Date Subject
Next Message Mark Dilger 2022-06-16 03:10:30 Re: Modest proposal to extend TableAM API for controlling cluster commands
Previous Message Michael Paquier 2022-06-16 03:07:03 Re: fix stats_fetch_consistency value in postgresql.conf.sample