Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Handle spurious CancelledKeyException errors coming from the NIO/sele…

…ctor implementation. This works around bug #4729342 in the Java bug parade.
  • Loading branch information...
commit a1b834b4ca9a42e5d2177fb6ddc82983da58f046 1 parent 2bb5e8d
Kresten Krab Thorup krestenkrab authored
12 src/main/java/erjang/driver/NIOChannelInfo.java
View
@@ -18,6 +18,7 @@
package erjang.driver;
+import java.nio.channels.CancelledKeyException;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.util.HashMap;
@@ -154,8 +155,17 @@ private int computeOps() {
*/
public void ready(SelectionKey key) {
final SelectableChannel ch = key.channel();
- final int readyOps = key.readyOps();
+ int readyOps;
+
+ try {
+ readyOps = key.readyOps();
+ } catch (CancelledKeyException e) {
+
+ // TODO: releaseNotify ?
+ return; // just ignore this condition
+ }
+
Interest[] ents = interest.values().toArray(
new Interest[interest.size()]);
11 src/main/java/erjang/driver/NIOSelector.java
View
@@ -19,6 +19,7 @@
package erjang.driver;
import java.io.IOException;
+import java.nio.channels.CancelledKeyException;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.ClosedSelectorException;
import java.nio.channels.SelectableChannel;
@@ -121,6 +122,10 @@ public void run0() {
try {
num = selector.select(10000);
+ } catch (CancelledKeyException e) {
+ // ignore this, as per
+ // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4729342
+
} catch (ClosedSelectorException e) {
e.printStackTrace();
return;
@@ -137,7 +142,11 @@ public void run0() {
// System.err.println("READY: "+key.channel()+":"+Integer.toBinaryString(key.readyOps()));
NIOChannelInfo req = (NIOChannelInfo) key.attachment();
- req.ready(key);
+ if (req == null) {
+ System.err.println("Internal error, SelectionKey's attachement is null");
+ } else {
+ req.ready(key);
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.