pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Jowett <oliver@opencloud.com>
To: Andras Kadinger <bandit@surfnonstop.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: implementing asynchronous notifications
Date: Mon, 11 Apr 2005 16:22:29 +1200
Message-ID: <4259FB85.10302@opencloud.com> (raw)
In-Reply-To: <Pine.LNX.4.44.0504110548390.13042-200000@ns.surfnonstop.com>
References: <Pine.LNX.4.44.0504110548390.13042-200000@ns.surfnonstop.com>

Andras Kadinger wrote:
> On Mon, 11 Apr 2005, Andras Kadinger wrote:
> 
>>I am unclear as to how to handle possible protocol errors (e.g. when what
>>we end up reading from the connection is not an 'A'sync Notify).  
>>Theoretically, in a working connection this should not happen though.
> 
> Yes, it could: reading the PostgreSQL protocol documentation, it says
> "frontends should always be prepared to accept and display NoticeResponse
> messages, even when the connection is nominally idle".
> 
> So I now added code to process Error 'N'otifications as well.

You also need to handle errors ('E'). Try shutting down a postmaster (-m
fast) while idle connections are around -- they'll get spontaneous FATAL
errors.

> +        try {
> +            executor.processNotifies();
> +        } catch (SQLException e) {};

Don't eat the exceptions, let them propagate.

(ugh, getNotifications() does not throw SQLException. We should probably
change that..)

> +            while (protoConnection.getTransactionState() == ProtocolConnection.TRANSACTION_IDLE && pgStream.getSocket().getInputStream().available()>0) {

Can you move that reference following into a method on PGStream?
(hasMessagePending() or something)

The test on transaction state is a bit misleading since the connection's
transaction state should never change inside the loop. Perhaps making
that a separate test would be clearer.

I'm not sure if available() is guaranteed to work on a socket stream
everywhere (it works fine here, though), but I suppose that at worst you
get the existing behaviour where you need to send a query.

Otherwise, seems fine!

-O



view thread (10+ messages)  latest in thread

Message-ID: <4259FB85.10302@opencloud.com>
Permalink:  ../4259FB85.10302@opencloud.com/
Also on:    postgresql.org/message-id/4259FB85.10302@opencloud.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-jdbc@postgresql.org
  Cc: oliver@opencloud.com, bandit@surfnonstop.com
  Subject: Re: implementing asynchronous notifications
  In-Reply-To: <4259FB85.10302@opencloud.com>
  References: <Pine.LNX.4.44.0504110548390.13042-200000@ns.surfnonstop.com> <4259FB85.10302@opencloud.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