Skip to content

Commit

Permalink
preventing CancelledKeyException, which randomly happens when selecto…
Browse files Browse the repository at this point in the history
…r selects an already closed key
  • Loading branch information
Tiago Cardoso authored and HoneyryderChuck committed Nov 14, 2017
1 parent 2ba5f79 commit 21a4172
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ext/nio4r/org/nio4r/Selector.java
Expand Up @@ -7,6 +7,7 @@
import java.nio.channels.Channel;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.CancelledKeyException;

import org.jruby.Ruby;
import org.jruby.RubyArray;
Expand Down Expand Up @@ -207,7 +208,14 @@ public synchronized IRubyObject select(ThreadContext context, IRubyObject timeou
Iterator selectedKeys = this.selector.selectedKeys().iterator();
while(selectedKeys.hasNext()) {
SelectionKey key = (SelectionKey)selectedKeys.next();
processKey(key);
try {
processKey(key);
} catch(CancelledKeyException ie) {
continue;
// TODO: what to do?
//throw runtime.newIOError(ie.getLocalizedMessage());
}

selectedKeys.remove();

if(block.isGiven()) {
Expand Down

0 comments on commit 21a4172

Please sign in to comment.