Skip to content

Regression in Socket#close - EBADF after unsuccessful connection #7483

@p0deje

Description

@p0deje

The issue was originally reported in #5709 and successfully fixed in JRuby 9.2.8. However, the regression was introduced in JRuby 9.3 and is still present in JRuby 9.4.

I cannot reopen original bug - hence new issue.

Environment Information

Provide at least:

  • JRuby 9.4.0.0
  • macOS 13 arm64

Other relevant info you may wish to add:

  • Installed or activated gems
  • Application/framework version (e.g. Rails, Sinatra)
  • Environment variables

Expected Behavior

Run the following script:

require 'socket'

sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM)
addr = Socket.pack_sockaddr_in(9250, '127.0.0.1')

begin
  sock.connect_nonblock(addr)
rescue Errno::EINPROGRESS
  IO.select(nil, [sock], nil, 1) # select socket for writing
  sock.getsockopt(Socket::SOL_SOCKET, Socket::SO_ERROR) # read any errors from last connection
  retry
rescue Errno::ECONNREFUSED, Errno::EINVAL
  puts 'Open!'
end

sock.close

This code works fine on MRI 3.0:

$ ruby socket.rb
Open!

Actual Behavior

The same code fails on JRuby 9.4:

$ ruby socket.rb
Open!
Errno::EBADF: Bad file descriptor - No message available
   Unable to find org/jruby/ext/socket/RubySocket.java to read failed line
  <main> at socket.rb:16

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