Skip to content

File::write uses nonblocking IO when MRI uses blocking #5663

@byteit101

Description

@byteit101

Environment

  • jruby 9.2.6.0 (2.5.3) 2019-02-11 15ba00b OpenJDK 64-Bit Server VM 25.201-b09 on 1.8.0_201-b09 +jit [linux-x86_64]
  • RHEL 7.6

Expected Behavior

MRI waits if nobody is reading the other side of a pty pair:

2.5.3 :001 > require 'pty'
 => true 
2.5.3 :002 > m,s = PTY.open
 => [#<IO:masterpty:/dev/pts/15>, #<File:/dev/pts/15>] 
2.5.3 :003 > 20.times{|i| puts "writing #{i}"; s.write("_" * 1000) }
writing 0
writing 1
writing 2
writing 3
writing 4
writing 5
writing 6
writing 7
writing 8
<hang until ctrl-c>

Actual Behavior

However JRuby appears to use non-blocking IO and thus throws an exception:

jruby-9.2.6.0 :001 > require 'pty'
 => true 
jruby-9.2.6.0 :002 > m,s = PTY.open; nil
 => nil 
jruby-9.2.6.0 :003 > 20.times{|i| puts "writing #{i}"; s.write("_" * 1000) }
writing 0
writing 1
writing 2
writing 3
writing 4
writing 5
writing 6
writing 7
writing 8
writing 9
writing 10
writing 11
writing 12
Traceback (most recent call last):
        9: from /home/byteit101/.rvm/rubies/jruby-9.2.6.0/bin/irb:13:in `<main>'
        8: from org/jruby/RubyKernel.java:1179:in `catch'
        7: from org/jruby/RubyKernel.java:1179:in `catch'
        6: from org/jruby/RubyKernel.java:1411:in `loop'
        5: from org/jruby/RubyKernel.java:1047:in `eval'
        4: from (irb):3:in `evaluate'
        3: from (irb):3:in `block in evaluate'
        2: from org/jruby/RubyIO.java:1429:in `write'
        1: from org/jruby/RubyIO.java:1472:in `write'
SystemCallError (Unknown error (SystemCallError) - No message available)
jruby-9.2.6.0 :004 >

It took me a bit to figure out that the errno was EAGAIN (Resource temporarily unavailable) (not sure why that wasn't in the exception message, another issue?)

I found this as the surprise exception causes a compatibility issue with Pry in a Pty to exit on large output (think ENV inspection, ~12k on my machine) in JRuby, but not under MRI as MRI never throws here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions