lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael McCandless (JIRA)" <>
Subject [jira] Commented: (LUCENE-669) finalize()-methods of FSDirectory.FSIndexInput and FSDirectory.FSIndexOutput try to close already closed file
Date Wed, 29 Nov 2006 23:30:23 GMT
    [ ] 
Michael McCandless commented on LUCENE-669:

Ugh!  This bug is clearly a heisenbug.

OK, I can also reproduce this on Windows when I use the IBM 1.5.0 JRE.
I can't repro with the Sun 1.5.0_07 JRE.

When I apply your patch, the IOException goes away.

Furthermore, my best efforts to get a standalone test to show the
error have failed.  I don't understand what precise tickling is
required to get the IOException to happen.

Finally, I found this spooky very recent thread on java-user that
looks very much like this error (and was never resolved):

I think in this case it was on Sun's JRE.  So I tried the test using
"java -server" but it didn't fail.  Sigh.

My conclusion is: double-closing a RandomAccessFile is dangerous!  And
quite possibly can cause problems for "real" use cases (ie, not just
when testing under Eclipse).

I will commit this patch.

I made a couple of tiny changes: changed the name to "isOpen" and
moved up the "isOpen = true" to be right after the file is actually

I also like the change to flush the buffer on finalize (if the file is
still open).

Thanks Michael!

> finalize()-methods of FSDirectory.FSIndexInput and FSDirectory.FSIndexOutput try to close
already closed file
> -------------------------------------------------------------------------------------------------------------
>                 Key: LUCENE-669
>                 URL:
>             Project: Lucene - Java
>          Issue Type: Bug
>          Components: Store
>            Reporter: Michael Busch
>         Assigned To: Michael Busch
>            Priority: Trivial
>         Attachments: FSDirectory_close_file2.patch
> Hi all,
> I found a small problem in FSDirectory: The finalize()-methods of FSDirectory.FSIndexInput
and FSDirectory.FSIndexOutput try to close the underlying file. This is not a problem unless
the file has been closed before by calling the close() method. If it has been closed before,
the finalize method throws an IOException saying that the file is already closed. Usually
this IOException would go unnoticed, because the GarbageCollector, which calls finalize(),
just eats it. However, if I use the Eclipse debugger the execution of my code will always
be suspended when this exception is thrown.
> Even though this exception probably won't cause problems during normal execution of Lucene,
the code becomes cleaner if we apply this small patch. Might this IOException also have a
performance impact, if it is thrown very frequently?
> I attached the patch which applies cleanly on the current svn HEAD. All testcases pass
and I verfied with the Eclipse debugger that the IOException is not longer thrown.

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
For more information on JIRA, see:


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message