public inbox for [email protected]  
help / color / mirror / Atom feed
From: Nathan Bossart <[email protected]>
To: Tom Lane <[email protected]>
Cc: Jacob Champion <[email protected]>
Cc: [email protected]
Subject: Re: alert clients when prepared statements are deallocated
Date: Wed, 3 Jun 2026 16:17:31 -0500
Message-ID: <aiCZ60MNyTQ8_4BE@nathan> (raw)
In-Reply-To: <ah9VKGwwlgqF-hi7@nathan>
References: <ahm_4eOKkkKJ3Gds@nathan>
	<[email protected]>
	<ahna7lre-xAn7DIS@nathan>
	<ah9VKGwwlgqF-hi7@nathan>

On Tue, Jun 02, 2026 at 05:11:52PM -0500, Nathan Bossart wrote:
> * I'm a little worried about race conditions involving a client trying to
> use a statement while a deallocation message is in flight, but I haven't
> identified anything concrete so far.  This is something I'd like to
> investigate some more, though.

Hm.  So there's actually a pretty obvious problem here.  Say a user
executes something like PQsendQuery(conn, "DISCARD ALL") and then tries to
execute an lo_* function (modified to use prepared statements) prior to
consuming the result.  In that case, the callback won't be called in time
and the LO function will fail.

My first instinct is that this is a showstopper for $subject, but perhaps
it is a rare enough scenario that we could live with documenting it.  My
suspicion is that it's uncommon for folks to asynchronously deallocate all
prepared statements, and I don't know why you'd use PQsendClosePrepared()
on statements named libpq_internal_*.  Nevertheless, this seems like a
rather large hole.

I think this calls into question whether moving the libpq interface to
prepared statements makes sense.  If we can't do that, I think we're pretty
much forced to keep the fast-path around forever or to accept a larger
performance hit.  In any case, I find it a little strange that there's not
a great way to use prepared statements internally in libpq, which is why
I'm chasing this a little more than perhaps I should.

-- 
nathan






view thread (13+ messages)  latest in thread

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 using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: alert clients when prepared statements are deallocated
  In-Reply-To: <aiCZ60MNyTQ8_4BE@nathan>

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

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