0

Rarely, my production application encounters an unexpected ClosedByInterruptException when invoking methods on a FileChannel. According to Java documentation, this occurs when the invoking thread is in the interrupted state. Interestingly, my application never interrupts any threads. This appears to be occurring from below the application. Some kind of system interrupt perhaps? Has anyone encountered this issue?

java.nio.channels.ClosedByInterruptException
    at java.nio.channels.spi.AbstractInterruptibleChannel.end( \
      AbstractInterruptibleChannel.java:184)
    at sun.nio.ch.FileChannelImpl.size(FileChannelImpl.java:314) 
    ...
Elliot
  • 189
  • 8
  • do you ever cancel any Futures? – jtahlborn Apr 10 '12 at 00:45
  • What is your envinronment? Something like Tomcat or a Plain Java Application? – dash1e Apr 10 '12 at 00:59
  • The application is a simple web application that manages file channels. The environment is Linux, Java 1.6, and Resin web container. The web application does no thread management. It doesn't use thread pool executors or futures. – Elliot Apr 10 '12 at 03:15

1 Answers1

0

Your application may never interrupt threads but the JVM may have done so for its own reasons. This is not at all likely to be a FileChannel bug, rather some unforeseen condition in the JVM itself.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • What's the difference between an "unexplained condition in the JVM that causes FileChannel to behave contrary to the documentation" and "there's a bug"? Not saying you're wrong, just that "an unexplained condition" is not really very helpful. – Steven Schlansker Apr 12 '12 at 01:55
  • 1
    @StevenSchlansker I didn't say there is or isn't a bug, I said it is unlikely to be a bug *in `FileChannel`*. It seems perfectly clear to me. – user207421 Apr 12 '12 at 02:02
  • Thanks for the confirmation. That is actually what I meant. When I said a bug in FileChannel, I didn't mean a bug in Java code, I meant a bug in native/JVM code somewhere under the FileChannel class. – Elliot Apr 12 '12 at 16:06
  • @Elliot That is actually *not* what *I* meant. If the JVM is interrupting your thread it is unlikely to be from anywhere 'under' the `FileChannel` class. It is almost certainly in a completely unrelated piece of code. – user207421 Apr 13 '12 at 04:23
  • Hmm, that's interesting. I'm not convinced that a Thread interrupt is occurring at all. I think the most likely scenario is a JVM-level exception occurring in native IO code during a FileChannel invocation. The ClosedByInterruptException may simply be the most applicable for the unexpected condition. Perhaps some kind of system interrupt is occurring. – Elliot Apr 13 '12 at 14:38
  • @Elliot You get a ClosedByInterruptException and you're not convinced an interrupt is happening? This is getting a lot more complicated than necessary to account for the phenomena. I've read all the Java and native NIO code at various times and I've never seen anything to support your assertion. – user207421 Apr 14 '12 at 02:39
  • I suspect a system interrupt, not a high-level Thread interrupt. That seems perfectly reasonable to me. Perhaps a system call is returning EINTR or some other interrupt primitive. I've noticed a few Java bugs along these lines on bugs.sun.com: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6427312. A bug search for EINTR returns many similar issues. – Elliot Apr 14 '12 at 06:19