Incorrect error code with TCPServer.new on JRuby 1.4.0

I have this script and I expect EADDRNOTAVAIL error but jruby gives
wrong
error code:

require ‘socket’
x = TCPServer.new “1.2.3.4”, 4000

Above script gives the following error on MRI on Mac (snow leopard),
ruby
1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]:

Errno::EADDRNOTAVAIL: Can’t assign requested address - bind(2)
from (irb):2:in initialize' from (irb):2:innew’
from (irb):2

Using jruby it gives a different error:

Errno::EADDRINUSE: Address already in use - Address in use
from (irb):3:in initialize' from (irb):3:innew’
from (irb):3

jruby version is:

jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2009-11-02 69fbfa3) (Java
HotSpot™ 64-Bit Server VM 1.6.0_15) [x86_64-java]

Is this a bug or different Ruby 1.8.7 patch level is causing this?

-vivek.

Hi Vivek,

Yeah, it looks like a bug in JRuby, wrong error on both Windows and
Linux, on all versions starting from 1.1.1 till 1.5dev
(haven’t checked earlier versions).

Please file a bug. And thanks for the report!

–Vladimir

On Fri, Nov 13, 2009 at 5:34 AM, Vivek P. [email protected]
wrote:

from (irb):2
Using jruby it gives a different error:
Errno::EADDRINUSE: Address already in use - Address in use
from (irb):3:in initialize' from (irb):3:in new’
from (irb):3
jruby version is:
jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2009-11-02 69fbfa3) (Java
HotSpot™ 64-Bit Server VM 1.6.0_15) [x86_64-java]
Is this a bug or different Ruby 1.8.7 patch level is causing this?
-vivek.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

I filed this bug and attached a tiny patch:

http://jira.codehaus.org/browse/JRUBY-4233

Hi Vivek, David,

After some additional investigation, things are not as easy and clear
as they seemed. :slight_smile:

The main problem is that JDK doesn’t provide different exceptions when
binding a socket. For both cases, when the local socket is in use and
when the attempt to bind to non-local socket is made, JDK will throw
BindException.

So, JRuby currently picks up the most typical and more important error
to report: Errno::EADDRINUSE.

I’m not sure how we could fix that, really. Well, BindException’s
messages are different in those two cases:

  • “Cannot assign requested address”
  • “Address already in use”

So, we could differentiate based on the message, but this is really
ugly. :slight_smile: Not to mention that it might not work on non-Sun JVMs and
possibly not all platforms.

Any other possibilities?

Thanks,
–Vladimir

On Fri, Nov 13, 2009 at 9:57 AM, David C.
[email protected] wrote:

(haven’t checked earlier versions).

require ‘socket’
Errno::EADDRINUSE: Address already in use - Address in use
To unsubscribe from this list, please visit:


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Another option would be to provide JRuby specific SocketImpl and
SocketImplFactory and for the native socket part can be implemented
using
FFI or JNA. The SocketImpl and SocketImplFactory can pretty much
delegate to
the default SocketImpl in JDK except the native part.

-vivek.

Thats right. JDK has just BindException and it will be a bad hack to fix
it
based on message.

At the minimum the message should be what bindingException.getMessage()
gives to convey at least what went wrong in the socket.bind().

-vivek.

FFI is sounding like a better and better option since there are
several socket-library issues that java.net.* seems incapable of
solving.

However, we still need a pure-Java mode for more restricted
environments and we should do whatever we can to minimize the number
of broken things in Pure-Java mode. Parsing messages is a super ugly
way, but it may be the hack-du-jour given the likelihood of Java
fixing this problem in the next 5-15 years…

Speaking of the message hack…is it possible that those Socket
messages are part of a message bundle or can be reflected out of
something? Then we would not need to worry about localization changes
breaking it.

If someone starts work on an ffi socket library we will do our best to
merge it in a meaningful way,

-Tom

On Fri, Nov 13, 2009 at 11:56 AM, Vivek P. [email protected]
wrote:

it based on message.

as they seemed. :slight_smile:
messages are different in those two cases:
Thanks,

Hi Vivek,
wrote:

from (irb):2:in `initialize’
Is this a bug or different Ruby 1.8.7 patch level is causing this?


blog: http://blog.enebo.com twitter: tom_enebo
mail: [email protected]


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Fri, Nov 13, 2009 at 1:01 PM, Thomas E Enebo [email protected]
wrote:

Speaking of the message hack…is it possible that those Socket
messages are part of a message bundle or can be reflected out of
something? Then we would not need to worry about localization changes
breaking it.

These messages are not part of Its coming straight from the native
layer.

-vivek.

Hi folks,

On Fri, Nov 13, 2009 at 10:47 PM, Vivek P. [email protected]
wrote:

These messages are not part of Its coming straight from the native layer.
-vivek.

Indeed, they don’t seem to be localized at any way. So I’ve fixed this
on JRuby master branch, now JRuby uses EADDRNOTAVAIL and EADDRINUSE
based on error message. Ugly, yes, but it works on both Linux and
Windows, and I assume on MacOS as well.

The RubySpecs for these cases have been added by David and me, so
we’ll soon know whether JRuby on MacOS works too.

Thanks for reporting this bug.

–Vladimir


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Excellent!

thanks for fixing,

-vivek.