Skip to content

Commit

Permalink
Mitigation for JRUBY-6576
Browse files Browse the repository at this point in the history
Because in JRuby, concurrent selects can trigger blocking mode
exceptions, I've modified IO.select logic to raise a concurrency
error when multiple threads try to select on the same sockets at
the same time (and fail to do so cleanly). At present, there's
no way to do this since we use these channels in both blocking and
nonblocking mode; we can't synchronize the blocking mode changes
with multiple threads all trying to do select operations.
  • Loading branch information
headius authored and dekellum committed Aug 3, 2012
1 parent 22a52eb commit cbbbf38
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/org/jruby/util/io/SelectBlob.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.IOException;
import java.nio.channels.CancelledKeyException;
import java.nio.channels.Channel;
import java.nio.channels.IllegalBlockingModeException;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
Expand Down Expand Up @@ -345,14 +346,22 @@ private void tidyUp() throws IOException {
if (readBlocking != null) {
for (int i = 0; i < readBlocking.length; i++) {
if (readBlocking[i] != null) {
((SelectableChannel) readIOs[i].getChannel()).configureBlocking(readBlocking[i]);
try {
((SelectableChannel) readIOs[i].getChannel()).configureBlocking(readBlocking[i]);
} catch (IllegalBlockingModeException ibme) {
throw runtime.newConcurrencyError("can not set IO blocking after select; concurrent select detected?");
}
}
}
}
if (writeBlocking != null) {
for (int i = 0; i < writeBlocking.length; i++) {
if (writeBlocking[i] != null) {
((SelectableChannel) writeIOs[i].getChannel()).configureBlocking(writeBlocking[i]);
try {
((SelectableChannel) writeIOs[i].getChannel()).configureBlocking(writeBlocking[i]);
} catch (IllegalBlockingModeException ibme) {
throw runtime.newConcurrencyError("can not set IO blocking after select; concurrent select detected?");
}
}
}
}
Expand Down

0 comments on commit cbbbf38

Please sign in to comment.