Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 5C01E632A26 for ; Thu, 27 Aug 2009 03:38:23 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 08911-04 for ; Thu, 27 Aug 2009 06:38:06 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail-ew0-f207.google.com (mail-ew0-f207.google.com [209.85.219.207]) by mail.postgresql.org (Postfix) with ESMTP id EF706632753 for ; Thu, 27 Aug 2009 03:36:44 -0300 (ADT) Received: by ewy3 with SMTP id 3so904682ewy.42 for ; Wed, 26 Aug 2009 23:36:43 -0700 (PDT) MIME-Version: 1.0 Received: by 10.210.136.17 with SMTP id j17mr8932153ebd.61.1251355003422; Wed, 26 Aug 2009 23:36:43 -0700 (PDT) In-Reply-To: <895e58dd0908262334k20544c1el292dc972f38c65b2@mail.gmail.com> References: <895e58dd0908241736q3575cdc2v461d879c5b5f9dcb@mail.gmail.com> <4A9334C4.2060503@opencloud.com> <895e58dd0908250815m1a8aada0qc9d3f0bde9c7a303@mail.gmail.com> <895e58dd0908250951m1aa4baabnf1695c9e681aa278@mail.gmail.com> <4A946B7A.60408@opencloud.com> <895e58dd0908260201g59762012ka2349eada052ab6d@mail.gmail.com> <4A95CE4B.5050107@opencloud.com> <895e58dd0908261737t20f5b7dbsd9ae546a34264a7@mail.gmail.com> <4A95D980.3070809@opencloud.com> <895e58dd0908262334k20544c1el292dc972f38c65b2@mail.gmail.com> Date: Wed, 26 Aug 2009 23:36:43 -0700 Message-ID: <895e58dd0908262336o4d3eb445te833a9f4cef2958b@mail.gmail.com> Subject: PGStream synchronization From: Maciek Sakrejda To: pgsql-jdbc@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.351 tagged_above=-10 required=5 tests=AWL=0.248, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200908/74 X-Sequence-Number: 19923 (missed CCing the list on my reply to Oliver) > How about, instead of using raw monitor synchronization to provide > mutual exclusion on access to the stream, we use a lock object (i.e. > something similar to java.util.concurrent.locks.Lock, though we can't > use exactly that class before 1.5 obviously), try to grab the lock > before close, and behave differently depending on if we succeeded or not. > > So the close logic can look something like this: > > =A0if (lock.tryLock()) { > =A0 =A0// we have exclusive access to the connection > =A0 =A0// do a normal shutdown > =A0 =A0try { > =A0 =A0 =A0sendTerminate(); > =A0 =A0 =A0stream.close(); > =A0 =A0} finally { > =A0 =A0 =A0lock.unlock(); > =A0 =A0} > =A0} else { > =A0 =A0// something is concurrently using the connection > =A0 =A0// just abruptly close the connection > =A0 =A0stream.close(); > =A0} > > In the concurrent case, we don't send Terminate, but we also don't risk > sending it at the wrong point in the stream. > > This means that a concurrent Connection.close() while something is > happening will result in an "unexpected client EOF" logged on the server > side, but that's almost what you want in this case anyway .. concurrent > close pretty much means "help, abort this!" .. > > -O > That's interesting. I think it's not quite in the spirit of the protocol, but there may not be much more we can do, and it's certainly a reasonable behavior. I'd like to spend some more time with the FEBE spec tomorrow and then I'll submit a patch based on this approach. Thanks, -- Maciek Sakrejda | Software Engineer | Truviso (650) 242-3500 Main (650) 242-3501 F msakrejda@truviso.com www.truviso.com