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).
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.
After some additional investigation, things are not as easy and clear
as they seemed.
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. Not to mention that it might not work on non-Sun JVMs and
possibly not all platforms.
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.
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,
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.
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.