Return-Path: Delivered-To: apmail-db-derby-dev-archive@www.apache.org Received: (qmail 96226 invoked from network); 19 Oct 2005 07:54:55 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 19 Oct 2005 07:54:55 -0000 Received: (qmail 38865 invoked by uid 500); 19 Oct 2005 07:54:53 -0000 Delivered-To: apmail-db-derby-dev-archive@db.apache.org Received: (qmail 38835 invoked by uid 500); 19 Oct 2005 07:54:53 -0000 Mailing-List: contact derby-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: Delivered-To: mailing list derby-dev@db.apache.org Received: (qmail 38826 invoked by uid 99); 19 Oct 2005 07:54:53 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Oct 2005 00:54:53 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=SPF_PASS,UNPARSEABLE_RELAY X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of mhn@cs.stanford.edu designates 171.67.73.10 as permitted sender) Received: from [171.67.73.10] (HELO agp.stanford.edu) (171.67.73.10) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Oct 2005 00:54:53 -0700 Received: from theory.stanford.edu ([171.64.78.10]) by agp.stanford.edu with esmtps (TLSv1:DES-CBC3-SHA:168) (Exim 4.43) id 1ES8mO-00002r-6k for derby-dev@db.apache.org; Wed, 19 Oct 2005 00:54:32 -0700 Received: from mail by theory.Stanford.EDU with spam-scanned (Exim 4.30) id 1ES8mM-00064m-Oo for derby-dev@db.apache.org; Wed, 19 Oct 2005 00:54:31 -0700 Received: from moa.stanford.edu ([171.64.78.81]) by theory.Stanford.EDU with esmtp (TLSv1:AES256-SHA:256) (Exim 4.30) id 1ES8mM-00064i-Mm; Wed, 19 Oct 2005 00:54:30 -0700 Received: from moa.Stanford.EDU (localhost.localdomain [127.0.0.1]) by moa.Stanford.EDU (8.12.11/8.12.11) with ESMTP id j9J7sS2q003496; Wed, 19 Oct 2005 00:54:28 -0700 Received: from localhost (mhn@localhost) by moa.Stanford.EDU (8.12.11/8.12.11/Submit) with ESMTP id j9J7sR0g003493; Wed, 19 Oct 2005 00:54:27 -0700 X-Authentication-Warning: moa.Stanford.EDU: mhn owned process doing -bs Date: Wed, 19 Oct 2005 00:54:27 -0700 (PDT) From: Mayur Naik X-X-Sender: mhn@moa.Stanford.EDU To: derby-dev@db.apache.org cc: Mayur Naik Subject: synchronization issues in Derby client code Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Scan-Signature: 4c131ba64fa6a0a0fa7484275de2528c X-Spam-Checker-Version: SpamAssassin 3.0.4-cs-csdcf (2005-06-05) on cs-smtp-3.Stanford.EDU X-Spam-Level: X-Virus-Checked: Checked by ClamAV on apache.org X-Old-Spam-Status: No, score=-104.9 required=7.0 tests=BAYES_00,USER_IN_WHITELIST autolearn=no version=3.0.4-cs-csdcf X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Hi David, Thanks for your feedback. I ran my race detection tool on Derby's client code and here is a summary of the results: http://suif.stanford.edu/~mhn/db-derby-10.1.1.0-src/classes/report.txt The tool found 319 possible bugs (distinct instances of missing synchronization). I will file all of them as a single JIRA bug item. Note that I analyzed only the client code, not the engine code. I hope to analyze the engine code as well at some point. Your feedback is welcome! In particular, I would be happy to hear from developers whether the races reported above are indeed bugs or harmless races. I hope to release the tool sometime in the near future (it still lacks documentation, a good user interface, etc.). Then, you should be able to run it on a regular basis. -- Mayur On 10/12/05, David W. Van Couvering wrote: > > > Hello, Mayur. This looks like *very* valuable information and I for one > appreciate you using Derby as a test bed for your work. > > It would be great to create a JIRA bug item for these race conditions > (I'm not sure if one item per race is overkill or not), and yes, > definitely we'd like to see more of this. > > Is this tool something that could be run on a regular basis and provide > reports? It is likely that new race conditions could get introduced as > new code is submitted... > > Thanks, > > David > > Mayur Naik wrote: > > > > Hello, > > > > I'm not sure if this is the right mailing list to post this. I'm a PhD > > student in Computer Science at Stanford University and I'm evaluating a > > static race detection tool I've developed on open source programs. I > > ran it to check the implementation of the java.sql.Connection interface > > in Derby and found 76 races, see: > > > > > http://suif.stanford.edu/~mhn/db-derby-10.1.1.0-src/connection_test/paos3/index.html > > > > > > The races are due to 12 missing synchronization's in > > > > org/apache/derby/client/am/Connection.java > > > > In particular, the following methods need to be synchronized: > > > > boolean getAutoCommit() > > boolean isClosed() > > int getTransactionIsolation() > > java.sql.SQLWarning getWarnings() > > java.sql.DatabaseMetaData getMetaData() > > boolean isReadOnly() > > String getCatalog() > > java.util.Map getTypeMap() > > int getHoldability() > > java.sql.PreparedStatement prepareStatement(String, int) > > java.sql.PreparedStatement prepareStatement(String, int[]) > > java.sql.PreparedStatement prepareStatement(String, String[]) > > > > Lack of synchronization in these methods can lead to unexpected > > behavior, for instance, the race: > > > > > http://suif.stanford.edu/~mhn/db-derby-10.1.1.0-src/connection_test/paos3/R432_trace.html > > > > > > is between the accesses to field warnings_ on lines 1614 and 0865: > > > > 1610 public void accumulateWarning(SqlWarning e) { > > 1611 if (warnings_ == null) { > > 1612 warnings_ = e; > > 1613 } else { > > 1614 warnings_.setNextException(e); > > 1615 } > > 1616 } > > > > 0864 public void clearWarningsX() throws SqlException { > > 0865 warnings_ = null; > > 0866 accumulated440ForMessageProcFailure_ = false; > > 0867 accumulated444ForMessageProcFailure_ = false; > > 0868 accumulatedSetReadOnlyWarning_ = false; > > 0869 } > > > > The latter method is called by clearWarnings(), which is synchronized, > > but the former method is called by 2 prepareStatement methods along > > paths which aren't sycnhronized. In particular, you can follow the "up" > > links in the above report and see that accumulateWarning(SqlWarning) is > > called by downgradeResultSetType(int) which is called by > > prepareStatementX(...) which is called by: > > > > java.sql.PreparedStatement prepareStatement(String, int) > > java.sql.PreparedStatement prepareStatement(String, String[]) > > > > Hence, if clearWarnings() and one of these prepareStatement methods are > > executed concurrently in separate threads on the same Connection object, > > there may be a null pointer exception. I don't know if such scenarios > > are possible, but the presence of synchronization in several methods in > > Connection.java suggests so. > > > > I would be happy if you could confirm/refute these bugs. Also, if you > > are interested in hearing about additional possible synchronization > > issues in Derby, I can check all of the Derby source code for races -- > > please let me know. > > > > Thanks! > > -- Mayur > > >