pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
To: tgl@sss.pgh.pa.us
Cc: alvherre@alvh.no-ip.org
Cc: daniele.varrazzo@gmail.com
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: Using PQexecQuery in pipeline mode produces unexpected Close messages
Date: Thu, 16 Jun 2022 10:41:21 +0900 (JST)
Message-ID: <20220616.104121.1499221777899715.horikyota.ntt@gmail.com> (raw)
In-Reply-To: <20220616.103422.2111499217922924771.horikyota.ntt@gmail.com>
References: <20220615182633.ztcoloh7xbicggot@alvherre.pgsql>
	<532816.1655319402@sss.pgh.pa.us>
	<20220616.103422.2111499217922924771.horikyota.ntt@gmail.com>

At Thu, 16 Jun 2022 10:34:22 +0900 (JST), Kyotaro Horiguchi <horikyota.ntt@gmail.com> wrote in 
> At Wed, 15 Jun 2022 14:56:42 -0400, Tom Lane <tgl@sss.pgh.pa.us> wrote in 
> > Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
> > > So, git archaeology led me to this thread
> > > https://postgr.es/m/202106072107.d4i55hdscxqj@alvherre.pgsql
> > > which is why we added that message in the first place.
> > 
> > Um.  Good thing you looked.  I doubt we want to revert that change now.
> > 
> > > Alternatives:
> > > - Have the client not complain if it gets CloseComplete in idle state.
> > >   (After all, it's a pretty useless message, since we already do nothing
> > >   with it if we get it in BUSY state.)
> > 
> > ISTM the actual problem here is that we're reverting to IDLE state too
> > soon.  I didn't try to trace down exactly where that's happening, but
> 
> Yes. I once visited that fact but also I thought that in the
> comparison with non-pipelined PQsendQuery, the three messages look
> extra.  Thus I concluded (at the time) that removing Close is enough
> here.
> 
> > I notice that in the non-pipeline case we don't go to IDLE till we've
> > seen 'Z' (Sync).  Something in the pipeline logic must be jumping the
> > gun on that state transition.
> 
- PQgetResult() resets the state to IDLE when not in pipeline mode.

D... the "not" should not be there.

+ 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..

regards.

-- 
Kyotaro Horiguchi
NTT Open Source Software Center





view thread (23+ messages)  latest in thread

Message-ID: <20220616.104121.1499221777899715.horikyota.ntt@gmail.com>
Permalink:  ../20220616.104121.1499221777899715.horikyota.ntt@gmail.com/
Also on:    postgresql.org/message-id/20220616.104121.1499221777899715.horikyota.ntt@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: horikyota.ntt@gmail.com, tgl@sss.pgh.pa.us, alvherre@alvh.no-ip.org, daniele.varrazzo@gmail.com, pgsql-hackers@lists.postgresql.org
  Subject: Re: Using PQexecQuery in pipeline mode produces unexpected Close messages
  In-Reply-To: <20220616.104121.1499221777899715.horikyota.ntt@gmail.com>
  References: <20220615182633.ztcoloh7xbicggot@alvherre.pgsql> <532816.1655319402@sss.pgh.pa.us> <20220616.103422.2111499217922924771.horikyota.ntt@gmail.com> <20220616.104121.1499221777899715.horikyota.ntt@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox