History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: JRUBY-891
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Martin Krauskopf
Votes: 0
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
JRuby

IO.select does not work properly with timeout

Created: 27/Apr/07 08:06 AM   Updated: 12/May/08 01:10 PM
Component/s: Core Classes/Modules
Affects Version/s: JRuby 1.0.0RC1
Fix Version/s: None

Time Tracking:
Not Specified

Environment: Linux
Issue Links:
Related
 


 Description  « Hide
There seems to be some problem with IO.select. We are using this call in the classic debugger in debug-commons and I'm not sure whether problem with classic debugger vs. JRuby interpreter are not caused by this call. I started with simple cases. Try this:

$cat tester.rb:

data, _, _ = IO.select([$stdin], nil, nil, 20)
$stdout.printf "data: #{data[0].gets}\n"

with Ruby. Start the program ruby tester.rb, enter immediately some charcter + Enter. Program immediately ends up.
Try the same with JRuby. Program always waits for 20s.

Leaving Major priority, not sure about consequences.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Thomas E Enebo - 27/Apr/07 03:28 PM
I looked into this one for a little while and here is a brain dump. I am going to drop this for now and perhaps come back to it if no one else does.

The way we get stdin is not compatible with nio. We basically (and even this is not neccesarily true) System.in. This is not an NIO friendly way to do this. It looks like we can new FileInputStream(FileDescriptor.in) and then we can get a selectable channel. Sounds easy until you see how many pesky details need to be rearranged to support this. We also implemented our own bufferedStream on top of stdin which extends a pushback stream.


Charles Oliver Nutter - 23/Oct/07 03:09 PM
There may be a good chance that just opening in/out/err as NIO channels will "just work" so we should give that a shot for 1.1.

Charles Oliver Nutter - 12/Jan/08 09:03 PM
I did some research on this, and unfortunately the stdio streams provided from Java are not selectable. You can turn them into channels, but you can't get selectable channels. So it appears we'll need to do something different for this.

Currently the selection code quietly does nothing if the target IO is not selectable. This is why it waits for 20 seconds no matter what; select doesn't actually select on anything. There are a couple alternatives to this:

  1. Have select return immediately or raise EAGAIN or another errno as though the selection did nothing. The downside is that loops looking for EAGAIN would loop forever, and other errnos may not be handled
  2. Raise a separate error saying that the IO in question is not selectable

And I'm open to suggestions. The bottom line, however, is that stdio is not selectable on the JVM. Bummer.


Thomas E Enebo - 14/Jan/08 11:10 AM
Perhaps we can implement a Selector for them and then use nio Pipe (with some scary thread magic)? One level less pretty too...

Charles Oliver Nutter - 15/Jan/08 04:19 PM
Less pretty is an understatement, but it might work. I don't want to implement it though

Charles Oliver Nutter - 15/Feb/08 12:55 PM
Removing target release from issues that fit any of the following criteria:
  • No known way to fix them
  • Java integration enhancements out of scope for 1.1 release
  • Other out of scope issues for 1.1

Vladimir Sizikov - 15/Feb/08 03:54 PM
Since the related issue was closed as duplicate of this one, it's worth noting here that not only STDIO is non-selectable, but also any file-based streams, which seems to be a important limitation.

Charles Oliver Nutter - 12/May/08 01:10 PM
There's going to be support in NIO2 for registering arbitrary selector providers, which could potentially make selecting on stdio possible. But for now this remains unfixable without native code.