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

stdlib: TCPServer#shutdown raises ENOTCONN #2240

Closed
PragTob opened this issue Nov 25, 2014 · 10 comments
Closed

stdlib: TCPServer#shutdown raises ENOTCONN #2240

PragTob opened this issue Nov 25, 2014 · 10 comments
Milestone

Comments

@PragTob
Copy link

PragTob commented Nov 25, 2014

Hi everyone :)

So I've been implementing some TCPServer stuff and I noticed an oddity/incompatibility between JRuby (1.7.16.1) and CRuby (2.1.5). Take this simple script:

require 'socket'

server = TCPServer.new 9090
server.shutdown

It runs just fine on CRuby, as I'd expect but it raises ENOTCONN on JRuby: Errno::ENOTCONN: Transport endpoint is not connected - Socket is not connected

Just checked jruby-head - it's also broken there.

That's a pity right now, as that's why my test suite fails for JRuby. Funnily changing shutdown to close (in my test suite, not this example script) works for JRuby but then CRuby fails... :-/

Thanks for JRuby :)
Tobi

@PragTob
Copy link
Author

PragTob commented Jul 21, 2015

Any update on this? Will it make it's way into 9k? I know it's nothing MAJOR but seems nice to fix :)

@etehtsea
Copy link
Contributor

etehtsea commented Nov 22, 2016

I'm getting ENOTCONN on every CRuby version I tried (2.0.0, 2.1.10, 2.2.5, 2.3.3).
@PragTob could you please check this again?

@PragTob
Copy link
Author

PragTob commented Nov 22, 2016

Still happening for me:

tobi@comfy ~ $ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
tobi@comfy ~ $ cat server.rb 
require 'socket'

server = TCPServer.new 9090
server.shutdown
tobi@comfy ~ $ ruby server.rb 

Maybe cause I'm on Linux?

tobi@comfy ~ $ uname -a
Linux comfy 4.4.0-47-generic #68-Ubuntu SMP Wed Oct 26 19:39:52 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

@PragTob
Copy link
Author

PragTob commented Nov 23, 2016

also still happening on JRuby (sorry had to fixup my JRuby install after some asdf problems):

tobi@comfy ~ $ ruby -v
jruby 9.1.6.0 (2.3.1) 2016-11-09 0150a76 OpenJDK 64-Bit Server VM 25.111-b14 on 1.8.0_111-8u111-b14-2ubuntu0.16.04.2-b14 +jit [linux-x86_64]
tobi@comfy ~ $ ruby server.rb 
Errno::ENOTCONN: Transport endpoint is not connected - Socket is not connected
  <main> at server.rb:4
tobi@comfy ~ $ 

@etehtsea
Copy link
Contributor

etehtsea commented Nov 23, 2016

@PragTob I checked on Linux and yes, CRuby behaves differently on Linux and macOS. On macOS behavior is the same as on JRuby. So I feel confused about what behaviour is expected.

@PragTob
Copy link
Author

PragTob commented Nov 23, 2016

I guess this would be a bug for CRuby itself then, in which they can figure out what the correct behavior is. I tend to think no error is correct but who am I to tell? :)

@etehtsea
Copy link
Contributor

etehtsea commented Nov 23, 2016

@PragTob I investigated this a little bit more and wanna say that this is completely legal to return ENOTCONN. On BSD/macOS shutdown call on a socket in LISTENING state raises error and doesn't change socket state, but on Linux it handled in a special way (as far as I understood it actually acts as close). Why don't you just use close over shutdown?

cc: @enebo @headius @kares

@PragTob
Copy link
Author

PragTob commented Nov 23, 2016

@etehtsea see the initial issue report:

That's a pity right now, as that's why my test suite fails for JRuby. Funnily changing shutdown to close (in my test suite, not this example script) works for JRuby but then CRuby fails... :-/

Sadly I don't have access to the application anymore, as it was a code challenge in a private github repo and I don't pay for github :D

That said the goal of JRuby is to be CRuby compatible so I think it should do the same. With CRuby being inconsistent it might be worthwhile to ask them though

@etehtsea
Copy link
Contributor

etehtsea commented Nov 24, 2016

@PragTob uhmm. This is strange that you had issues with close, but anyway, according to documentation:

shutdown([how]) => 0
Calls shutdown(2) system call.

shutdown method is no more than wrapper around shutdown(2) system call and my comment above is about its behavior. So this inconsistency is not CRuby fault. JRuby mostly uses java APIs and I think there is no sense to emulate system calls behavior across different OSes.

shutdown(Input|Output) methods methods that used in JRuby's shutdown implementation don't close sockets in LISTENING state. This is why TCPServer#shutdown is considered unsupported under JRuby.

@headius am I right?

@headius
Copy link
Member

headius commented Jul 9, 2020

@etehtsea Yes, I would say you are right.

We do stretch to try to emulate CRuby on a "bug-for-bug basis" but asking to shut down a socket that's not connected seems like a bridge too far.

This is also very old now, so I'm going to call it stale and mark it Won't Fix.

@headius headius closed this as completed Jul 9, 2020
@headius headius added this to the Won't Fix milestone Jul 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants