Project

General

Profile

Actions

Feature #6583

closed

Improve socket exception message when bind() fails

Added by drbrain (Eric Hodel) almost 12 years ago. Updated about 11 years ago.

Status:
Closed
Target version:
[ruby-core:45617]

Description

=begin
If the user tries to bind a port that is already in use the user does not receive any notification of which port (and address) failed. When multiple connections are being made makes it difficult to determine which connection was not correctly bound.

For example, WEBrick binds both IPv4 and IPv6 sockets. If one of the ports is already bound you will receive a confusing error message.

This patch adds the port and address to the error message:

$ cat test.rb
require 'socket'

TCPServer.new '0.0.0.0', 5900
$ make runruby
./miniruby -I./lib -I. -I.ext/common ./tool/runruby.rb --extout=.ext -- --disable-gems ./test.rb
./test.rb:3:in initialize': Address already in use - bind(2) for "0.0.0.0" port 5900 (Errno::EADDRINUSE) from ./test.rb:3:in new'
from ./test.rb:3:in `'
make: *** [runruby] Error 1

Current behavior:

$ ruby test.rb
test.rb:3:in initialize': Address already in use - bind(2) (Errno::EADDRINUSE) from test.rb:3:in new'
from test.rb:3:in `'

=end


Files

socket.improve_bind_error.patch (5.3 KB) socket.improve_bind_error.patch drbrain (Eric Hodel), 06/13/2012 11:42 AM
socket.improve_bind_error.2.patch (12.7 KB) socket.improve_bind_error.2.patch drbrain (Eric Hodel), 07/04/2012 11:07 AM

Updated by drbrain (Eric Hodel) almost 12 years ago

This updated patch adds three new methods rsock_sys_fail_host_port, rsock_sys_fail_path and rsock_sys_fail_sockaddr for raising exceptions from more than bind().

Additionally, rb_sys_fail() calls were audited and names of system calls were added where they were missing, and updated where incomplete (lacking manual page designator).

Updated by akr (Akira Tanaka) almost 12 years ago

  • Assignee set to akr (Akira Tanaka)
Actions #3

Updated by mame (Yusuke Endoh) almost 12 years ago

  • Status changed from Open to Assigned

Updated by akr (Akira Tanaka) over 11 years ago

  • Target version changed from 2.0.0 to 2.6
Actions #5

Updated by akr (Akira Tanaka) about 11 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r40149.
Eric, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • ext/socket: Improve socket exception message to show socket address.
    [ruby-core:45617] [Feature #6583] proposed Eric Hodel.

  • ext/socket/rubysocket.h (rsock_sys_fail_host_port): Declared.
    (rsock_sys_fail_path): Ditto.
    (rsock_sys_fail_sockaddr): Ditto.

  • ext/socket/udpsocket.c (udp_connect): Use rsock_sys_fail_host_port.
    (udp_bind): Ditto.
    (udp_send): Ditto.

  • ext/socket/init.c (rsock_init_sock): Specify a string for rb_sys_fail
    argument.
    (make_fd_nonblock): Ditto.
    (rsock_s_accept): Ditto.

  • ext/socket/ipsocket.c (init_inetsock_internal): Use
    rsock_sys_fail_host_port.

  • ext/socket/socket.c (rsock_sys_fail_host_port): Defined.
    (rsock_sys_fail_path): Ditto.
    (rsock_sys_fail_sockaddr): Ditto.
    (setup_domain_and_type): Use rsock_sys_fail_sockaddr.
    (sock_connect_nonblock): Ditto.
    (sock_bind): Ditto.
    (sock_gethostname): Specify a string for rb_sys_fail argument.
    (socket_s_ip_address_list): Ditto.

  • ext/socket/basicsocket.c (bsock_shutdown): Specify a string for
    rb_sys_fail argument.
    (bsock_setsockopt): Use rsock_sys_fail_path.
    (bsock_getsockopt): Ditto.
    (bsock_getpeereid): Refine the argument for rb_sys_fail.

  • ext/socket/unixsocket.c (rsock_init_unixsock): Use
    rsock_sys_fail_path.
    (unix_path): Ditto.
    (unix_send_io): Ditto.
    (unix_recv_io): Ditto.
    (unix_addr): Ditto.
    (unix_peeraddr): Ditto.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0