-
-
Notifications
You must be signed in to change notification settings - Fork 925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JRuby 1.7.20.1 Socket.tcp, Addrinfo.tcp, etc. mistake port for protocol #3067
Comments
Nice! Investigating. |
The code as written in JRuby was attempting to use the "protocol" argument (port) as "protocol family". This was a misunderstanding on my part. Protocol here means "service" and is passed as the third argument to socket(2). Interestingly, simply ignoring this parameter appears to work fine. The socket still must be bound to a remote host and port anyway. I believe the socket(2) parameter is used for purposes that have no equivalent on JDK. |
Ok, I've figured it out. The logic here goes like this:
Since we already have branching logic based on domain and family to choose the right kind of IO channel, I am not sure we need to do anything with the protocol (and I'm not sure we can do anything). There are probably some exotic domain+family combinations that have multiple protocols, but it appears to be a relic. My change will properly save and report protocol from Addrinfo and within Socket constructors, but will not use that protocol for any purpose. This appears to pass your case and may be as close as we need to get. |
I have fixed this for 9k. I'll see if it's easy to do for 1.7.x as well. |
Conflicts: core/src/main/java/org/jruby/ext/socket/Addrinfo.java
Fixed for both 9k.rc2 and 1.7.21. |
Observed Behavior
Root Cause
JRuby's Addrinfo implementation incorrectly returns the port number as the protocol:
Source 1.7.20.1:
https://github.com/jruby/jruby/blob/1.7.20.1/core/src/main/java/org/jruby/ext/socket/Addrinfo.java#L225-L228
It still is a problem in 9.0.0.0.rc1: https://github.com/jruby/jruby/blob/9.0.0.0.rc1/core/src/main/java/org/jruby/ext/socket/Addrinfo.java#L263-L266
MRI Behavior
afamily 2 is PF_INET (ipv4), socktype of 1 is SOCK_STREAM, and protocol 6 is TCP (according to /etc/protocols on Mac OS X)
The text was updated successfully, but these errors were encountered: