Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4f0fdb8098ff
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c83120b9e5c8
Choose a head ref
  • 2 commits
  • 3 files changed
  • 2 contributors

Commits on Jun 4, 2016

  1. Copy the full SHA
    171dc40 View commit details

Commits on Jun 28, 2016

  1. Merge pull request #3952 from mohamedhafez/cleankeys_pr2

    Ensure that Selectors from SelectorPool don't have old keys in them
    headius authored Jun 28, 2016
    Copy the full SHA
    c83120b View commit details
8 changes: 0 additions & 8 deletions core/src/main/java/org/jruby/RubyThread.java
Original file line number Diff line number Diff line change
@@ -1768,14 +1768,6 @@ public boolean select(Channel channel, OpenFile fptr, int ops, long timeout) {
// so that we can ensure one failing does not affect the others
// running.

// clean up the key in the selector
try {
if (key != null) key.cancel();
if (currentSelector != null) currentSelector.selectNow();
} catch (Exception e) {
// ignore
}

// shut down and null out the selector
try {
if (currentSelector != null) {
21 changes: 1 addition & 20 deletions core/src/main/java/org/jruby/util/io/SelectExecutor.java
Original file line number Diff line number Diff line change
@@ -50,17 +50,12 @@ IRubyObject selectCall(ThreadContext context) throws IOException {
}

IRubyObject selectEnd(ThreadContext context) throws IOException {
fdTerm(readKeyList);
fdTerm(writeKeyList);
fdTerm(errorKeyList);

if (selectors != null) {
for (int i = 0; i < selectors.size(); i++) {
Selector selector = selectors.get(i);
// if it is a JDK selector, cache it
if (selector.provider() == SelectorProvider.provider()) {
// clear cancelled keys (with selectNow) and return to pool
selector.selectNow();
// return to pool
context.runtime.getSelectorPool().put(selector);
} else {
selector.close();
@@ -277,20 +272,6 @@ private boolean fdIsSet(List<SelectionKey> fds, ChannelFD fd, int operations) {
return false;
}

private void fdTerm(List<SelectionKey> keys) {
if (keys == null) return;
for (int i = 0; i < keys.size(); i++) {
SelectionKey key = keys.get(i);
killKey(key);
}
}

private void killKey(SelectionKey key) {
try {
if (key.isValid()) key.cancel();
} catch (Exception e) {}
}

private SelectionKey trySelectRead(ThreadContext context, ChannelFD fd) throws IOException {
if (fd.chSelect != null) {
return registerSelect(getSelector(context, fd.chSelect), fd, fd.chSelect, READ_ACCEPT_OPS);
15 changes: 13 additions & 2 deletions core/src/main/java/org/jruby/util/io/SelectorPool.java
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@
package org.jruby.util.io;

import java.io.IOException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.util.ArrayList;
import java.util.List;
@@ -38,6 +39,7 @@
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Iterator;

/**
* This is a simple implementation of a hard-referenced java.nio.channels.Selector
@@ -82,7 +84,16 @@ public synchronized Selector get(SelectorProvider provider) throws IOException{
*
* @param selector the selector to put back
*/
public synchronized void put(Selector selector) {
public void put(Selector selector) {
Iterator<SelectionKey> key_iterator = selector.keys().iterator();
while(key_iterator.hasNext()) key_iterator.next().cancel();

try {
selector.selectNow();
} catch (Exception e) {
//ignore
}

returnToPool(selector);
}

@@ -130,7 +141,7 @@ private Selector retrieveFromPool(SelectorProvider provider) throws IOException
return selector;
}

private void returnToPool(Selector selector) {
private synchronized void returnToPool(Selector selector) {
openSelectors.remove(selector);
if (selector.isOpen()) {
SelectorProvider provider = selector.provider();