Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 7A7F3632707 for ; Wed, 26 Aug 2009 21:55:46 -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 45653-08 for ; Thu, 27 Aug 2009 00:55:26 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from tremor.opencloud.co.nz (tremor.opencloud.co.nz [131.203.101.230]) by mail.postgresql.org (Postfix) with ESMTP id 770FD632FEE for ; Wed, 26 Aug 2009 21:55:34 -0300 (ADT) Received: from 122-57-44-76.jetstream.xtra.co.nz ([122.57.44.76] helo=[192.168.1.3]) by tremor.opencloud.co.nz with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1MgTH0-0003cF-66; Thu, 27 Aug 2009 12:55:30 +1200 Message-ID: <4A95D980.3070809@opencloud.com> Date: Thu, 27 Aug 2009 12:55:28 +1200 From: Oliver Jowett User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Maciek Sakrejda CC: pgsql-jdbc@postgresql.org Subject: Re: PGStream synchronization 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> In-Reply-To: <895e58dd0908261737t20f5b7dbsd9ae546a34264a7@mail.gmail.com> X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200908/73 X-Sequence-Number: 19922 Maciek Sakrejda wrote: > Any thoughts? 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: if (lock.tryLock()) { // we have exclusive access to the connection // do a normal shutdown try { sendTerminate(); stream.close(); } finally { lock.unlock(); } } else { // something is concurrently using the connection // just abruptly close the connection stream.close(); } 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