Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E95DCFAA6 for ; Wed, 10 Apr 2013 08:05:23 +0000 (UTC) Received: (qmail 1437 invoked by uid 500); 10 Apr 2013 08:05:23 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 1290 invoked by uid 500); 10 Apr 2013 08:05:19 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 1190 invoked by uid 99); 10 Apr 2013 08:05:15 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Apr 2013 08:05:15 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Apr 2013 08:05:13 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id A133123888FD; Wed, 10 Apr 2013 08:04:52 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1466362 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBStreamControl.java Date: Wed, 10 Apr 2013 08:04:52 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130410080452.A133123888FD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kahatlen Date: Wed Apr 10 08:04:52 2013 New Revision: 1466362 URL: http://svn.apache.org/r1466362 Log: DERBY-6092: IOException when closing LOBFile at end of transaction A bug in Java 5 may cause IOException if two threads attempt to close the same RandomAccessFile at the same time. Avoid this situation by removing the LOBFile from the list of open files before closing it from LOBStreamControl's finalizer. Then the cleanup code at the end of the transaction won't find the file and try to close it if the finalizer is about to close it. Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBStreamControl.java Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBStreamControl.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBStreamControl.java?rev=1466362&r1=1466361&r2=1466362&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBStreamControl.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBStreamControl.java Wed Apr 10 08:04:52 2013 @@ -531,8 +531,22 @@ class LOBStreamControl { * @throws IOException if the file cannot be closed or deleted */ private void releaseTempFile(LOBFile file) throws IOException { - file.close(); + // Remove the file from the list of open files *first*, then close it. + // + // Why? This code may be called from finalize(), and may end up running + // at the same time the transaction is committed or rolled back. If two + // threads call RandomAccessFile.close() at the same time, Java 5 could + // fail (see DERBY-6092). By removing it from the list before closing + // it, we make sure that EmbedConnection.clearLOBMapping() won't see + // it if we get to the file first. Conversely, if clearLOBMapping() + // gets to it first, the call to removeLobFile() will block until + // clearLOBMapping() is done, so we won't attempt to close the file + // until after clearLOBMapping() is done, rather than at the same time. + // + // Calling close() concurrently is safe on Java 6 and newer, after the + // fix for http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6322678 . conn.removeLobFile(file); + file.close(); deleteFile(file.getStorageFile()); }