Skip to content

NPE retrieving IO channel #9324

@kares

Description

@kares

JRuby 10.0.4.0 errors out on the following script on TCPServer#accept -> IO -> OpenFile#channel()

require 'socket'

# Use more aggressive timing: don't wait for accept at all
500.times do |i|
  tcp = TCPServer.new("127.0.0.1", 0)
  port = tcp.connect_address.ip_port

  server = Thread.new do
    Thread.current.abort_on_exception = true
    Thread.current.report_on_exception = true
    loop do
      c = tcp.accept
      c.close
    end
  rescue IOError, Errno::EBADF, Errno::EINVAL, Errno::ECONNABORTED, Errno::ENOTSOCK, Errno::ECONNRESET
    # expected
  end

  # Multiple rapid connects
  10.times do
    Thread.new {
      begin; s = TCPSocket.new("127.0.0.1", port); s.close; rescue; end
    }
  end
  Thread.pass

  tcp.close rescue nil
  server.join(1)
  server.kill if server.alive?
end
STDERR.puts "done"
Unhandled Java exception: java.lang.NullPointerException: Cannot read field "ch" because "this.fd" is null
java.lang.NullPointerException: Cannot read field "ch" because "this.fd" is null
                  channel at org/jruby/util/io/OpenFile.java:2524
               getChannel at org/jruby/RubyIO.java:433
   getServerSocketChannel at org/jruby/ext/socket/RubyTCPServer.java:295
                   accept at org/jruby/ext/socket/RubyTCPServer.java:160
                     call at org/jruby/ext/socket/RubyTCPServer$INVOKER$i$0$0$accept.gen:-1
                     call at org/jruby/runtime/callsite/CachingCallSite.java:193
      invokeOther0:accept at tmp//tmp/reproducer_stderr.rb:16
  RUBY$block$\=\^main\_$2 at tmp//tmp/reproducer_stderr.rb:16
              yieldDirect at org/jruby/runtime/CompiledIRBlockBody.java:151
            yieldSpecific at org/jruby/runtime/IRBlockBody.java:72
            yieldSpecific at org/jruby/runtime/Block.java:158
                     loop at org/jruby/RubyKernel.java:1725
                     call at org/jruby/RubyKernel$INVOKER$s$0$0$loop.gen:-1
                     call at org/jruby/runtime/callsite/CachingCallSite.java:208
                fcallIter at org/jruby/runtime/callsite/CachingCallSite.java:230
        invokeOther6:loop at tmp//tmp/reproducer_stderr.rb:15
  RUBY$block$\=\^main\_$1 at tmp//tmp/reproducer_stderr.rb:15
               callDirect at org/jruby/runtime/CompiledIRBlockBody.java:141
                     call at org/jruby/runtime/IRBlockBody.java:64
                     call at org/jruby/runtime/IRBlockBody.java:58
                     call at org/jruby/runtime/Block.java:144
                     call at org/jruby/RubyProc.java:354
                      run at org/jruby/internal/runtime/RubyRunnable.java:111
                      run at java/lang/Thread.java:1583

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions