public inbox for [email protected]  
help / color / mirror / Atom feed
From: Pawel Veselov <[email protected]>
To: rob stone <[email protected]>
Cc: List <[email protected]>
Subject: Re: PGConnection.getNotifications(0) doesn't block
Date: Fri, 4 Aug 2023 11:49:34 +0200
Message-ID: <CAMnJ+BdtQBsZFqD93R4g+rx+28htsZ6uRBe6umPagi2JzuGR=A@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <CAMnJ+Bf7STMy2DwKjT12dxT-j+Han1KoVSkmFZ9Otuwd6to+DA@mail.gmail.com>
	<[email protected]>

> > I'm implementing a bit that is expected to wait for published channel
> > notifications,
> > and once there are any - process them.
> >
> > I'm using PGConnection.getNotifications(0), but that immediately
> > returns an empty
> > array, and doesn't block like JavaDoc says it should.
> >
> > I'm on 42.6.0.
> >
> > What am I missing?
> >
> > Thank you.
> Have you read the JDBC docs
> https://jdbc.postgresql.org/documentation/server-prepare
> which has a section about Listen/Notify?

I've read https://access.crunchydata.com/documentation/pgjdbc/42.1.1/listennotify.html
instead. I've read the Listen/Notify section in
https://jdbc.postgresql.org/documentation/server-prepare just now,
which carries identical text. I've also read the JavaDocs for the method(s).

All these sources agree or at least don't contradict that
getNotifications(0) should block without conditions,
and none mention that the connection must be in the IDLE
transaction state.

For that matter, even
https://www.postgresql.org/docs/current/sql-listen.html doesn't say
anything about the fact that notifications are only received/can be
read if the connection is in that state. It only mentions that the
 transaction that executed LISTEN must be first
committed for that connection to start seeing notifications (for
subscribed channel).

What I was effectively doing on that connection is:
BEGIN
LISTEN
COMMIT
BEGIN
UPDATE xxx;
<poll for notifications>

I've created this for tracking: https://github.com/pgjdbc/pgjdbc/issues/2937





view thread (4+ messages)

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]
  Subject: Re: PGConnection.getNotifications(0) doesn't block
  In-Reply-To: <CAMnJ+BdtQBsZFqD93R4g+rx+28htsZ6uRBe6umPagi2JzuGR=A@mail.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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox