Project

General

Profile

Actions

Feature #6583

closed

Improve socket exception message when bind() fails

Added by drbrain (Eric Hodel) over 12 years ago. Updated over 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
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0