Skip to content
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

Socket.new fails with IPPROTO_TCP #785

Closed
jlee-r7 opened this issue Jun 3, 2013 · 8 comments
Closed

Socket.new fails with IPPROTO_TCP #785

jlee-r7 opened this issue Jun 3, 2013 · 8 comments

Comments

@jlee-r7
Copy link

jlee-r7 commented Jun 3, 2013

irb(main):003:0> RUBY_DESCRIPTION
=> "jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on OpenJDK 64-Bit Server VM 1.7.0_21-b02 [linux-amd64]"
irb(main):004:0> s = Socket.new(::Socket::AF_INET, ::Socket::SOCK_STREAM, ::Socket::IPPROTO_TCP)
ArgumentError: unsupported protocol family `__UNKNOWN_CONSTANT__'
        from org/jruby/ext/socket/RubySocket.java:185:in `initialize'
        from org/jruby/RubyIO.java:856:in `new'
        from (irb):4:in `evaluate'
        from org/jruby/RubyKernel.java:1093:in `eval'
        from org/jruby/RubyKernel.java:1489:in `loop'
        from org/jruby/RubyKernel.java:1254:in `catch'
        from org/jruby/RubyKernel.java:1254:in `catch'
        from /home/egypt/.rvm/rubies/jruby-1.7.4/bin/irb:13:in `(root)'

All of the constants are defined and have correct values.

irb(main):010:0> p ::Socket::AF_INET, ::Socket::SOCK_STREAM, ::Socket::IPPROTO_TCP
2
1
6

Replacing IPPROTO_TCP with 0 is a workaround.

irb(main):011:0> s = Socket.new(::Socket::AF_INET, ::Socket::SOCK_STREAM, 0)
=> #<Socket:fd 47>
@jlee-r7
Copy link
Author

jlee-r7 commented Jun 3, 2013

jruby 1.6.8 does not have this problem:

$ jruby-1.6.8 -rsocket -e " p RUBY_DESCRIPTION, Socket.new(::Socket::AF_INET, ::Socket::SOCK_STREAM, ::Socket::IPPROTO_TCP)" 
"jruby 1.6.8 (ruby-1.8.7-p357) (2013-06-03 fffffff) (OpenJDK 64-Bit Server VM 1.7.0_21) [linux-amd64-java]"
#<Socket:0x6fdb48f5>

@BanzaiMan
Copy link
Member

Error is platform-dependent. On Mac OS X, the unknown protocol is PF_NS. The error arises because we are using the IP protocol value (6 in this case) to look up from the protocol family table. https://github.com/jruby/jruby/blob/1.7.4/src/org/jruby/ext/socket/RubySocket.java#L393

@ghost ghost self-assigned this Jun 18, 2013
@BanzaiMan
Copy link
Member

@atambo
Copy link
Member

atambo commented Jul 23, 2013

@BanzaiMan, do you know which AddressFamily's should trigger looking up a ProtocolFamily versus a IPProto? My guess is it switches based on this if statement or this switch statement:

https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/ext/socket/RubySocket.java#L359-L365
https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/ext/socket/RubySocket.java#L571-L579

So when AddressFamily is INET, INET6, or UNSPEC then use IPProto and when AddressFamily is UNIX or LOCAL use ProtocolFamily? What about when AddressFamily is none of the above?

@BanzaiMan
Copy link
Member

@atambo It is not clear to me, to be honest. I'd consult @wmeissner first.

@headius
Copy link
Member

headius commented Jul 23, 2013

A side question: why use Socket instead of TCPSocket? We are somewhat limited in what features of Socket we can provide since JDK does not provide a raw non-TCP socket for us to customize.

@brndnblck
Copy link

@headius TCPSocket automatically connects on instantiation. If you don't want that, that's one reason to use Socket instead. I've actually been running into this issue as well.

jlee-r7 pushed a commit to rapid7/raptor-io that referenced this issue Dec 2, 2013
@rtyler
Copy link

rtyler commented Aug 7, 2015

@jlee-r7 as far as I can tell this issue is no longer reproducible. @BanzaiMan does allude to it being platform dependent but jnr-constants and JRuby have changed quite a bit in the past few years :)

I'm not able to repro this (on Linux though), so I'm going to close this. If you can still reproduce it with 9k please re-open!

@rtyler rtyler closed this as completed Aug 7, 2015
@enebo enebo added this to the Invalid or Duplicate milestone Aug 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants