Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U5KuY-0001zP-2E for pgsql-jdbc@arkaria.postgresql.org; Tue, 12 Feb 2013 18:48:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1U5KuX-0006fy-Gz for pgsql-jdbc@arkaria.postgresql.org; Tue, 12 Feb 2013 18:48:57 +0000 Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U5KuW-0006fJ-Gf for pgsql-jdbc@postgresql.org; Tue, 12 Feb 2013 18:48:56 +0000 Received: from smtp-outbound-2.vmware.com ([208.91.2.13]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U5KuT-0002rC-Gt for pgsql-jdbc@postgresql.org; Tue, 12 Feb 2013 18:48:56 +0000 Received: from sc9-mailhost2.vmware.com (sc9-mailhost2.vmware.com [10.113.161.72]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id 8133A288FB; Tue, 12 Feb 2013 10:48:51 -0800 (PST) Received: from zcs-prod-ext-mta-2.vmware.com (zcs-prod-ext-mta-2.vmware.com [10.113.62.224]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 7D79AB0460; Tue, 12 Feb 2013 10:48:51 -0800 (PST) Received: from localhost (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTP id E5316C15BD; Tue, 12 Feb 2013 10:48:50 -0800 (PST) X-Virus-Scanned: amavisd-new at zcs-prod-ext-mta-2.vmware.com Received: from zcs-prod-ext-mta-2.vmware.com ([127.0.0.1]) by localhost (zcs-prod-ext-mta-2.vmware.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EnEVsnT39QEF; Tue, 12 Feb 2013 10:48:50 -0800 (PST) Received: from zcs-prod-ext-mta-2.vmware.com (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTP id BEBFCC1521; Tue, 12 Feb 2013 10:48:50 -0800 (PST) Received: from [192.168.1.90] (unknown [10.113.62.14]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTPSA; Tue, 12 Feb 2013 10:48:49 -0800 (PST) Message-ID: <511A8E90.4010202@vmware.com> Date: Tue, 12 Feb 2013 20:48:48 +0200 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130116 Icedove/10.0.12 MIME-Version: 1.0 To: Florent Guillaume CC: Bryan Varner , "pgsql-jdbc@postgresql.org" Subject: Re: PostgreSQL XAResource & GlassFish 3.1.2.2 References: <511A2C7F.1040104@vmware.com> <511A675B.3020207@polarislabs.com> <511A8BAC.7080400@vmware.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -6.9 (------) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org On 12.02.2013 20:41, Florent Guillaume wrote: > On Tue, Feb 12, 2013 at 7:36 PM, Heikki Linnakangas > wrote: >> I see. I think there's yet another potential explanation: even if glassfish >> is careful to invoke the end() only after start() has fully finished in the >> other thread, the java memory model does not guarantee that the effects of >> the end() in one thread are visible to the other thread doing the start(). >> The update of the PGXAConnection's state-variable might be sitting in the >> CPU cache of the CPU running the first thread, not yet visible to the second >> thread. > > That's the whole point of volatile since Java 5, it enforces a barrier > and "happens-before" semantics. > >> However, I'm not sure if glassfish could guarantee that the start() >> has really finished before end() is called, without using some operation >> that would also force the CPU cache to be flushed, making the effects >> visible. >> >> In any case, it seems like we should add "synchronized" to all the public >> methods in PGXAConnection. The performance penalty should be minimal, and it >> would fix any race conditions of that sort. > > For Java 5+ this is really overkill. Well, volatile will only fix the issue if it's indeed "just" because of weak memory ordering issues. However, if the cause is a genuine race condition where glassfish calls end() in one thread before the start() in another thread has ran to completion, as Bryan suspected, then volatile is not enough. Besides, it would be good for PGXAConnection to be thread-safe in general, like the rest of the JDBC driver. - Heikki -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc