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

JRuby 9.0.0.0.pre2 starts hanging while reading from a socket #2957

Closed
deepj opened this Issue May 19, 2015 · 7 comments

Comments

Projects
None yet
3 participants
@deepj
Copy link

deepj commented May 19, 2015

I have added running Puma server tests under JRuby 9k (see puma/puma#701 including Travis https://travis-ci.org/puma/puma/jobs/63116729). There is one test there causing that hanging: https://github.com/puma/puma/blob/master/test/test_puma_server.rb#L207

I haven't debug it deeply but it seems it is caused by reading from a socket. I got the same issue as on Travis on my local machine with these settings:

$ ruby -v
jruby 9.0.0.0.pre2 (2.2.2) 2015-04-28 2755ae0 Java HotSpot(TM) 64-Bit Server VM 25.45-b02 on 1.8.0_45-b14 +jit [darwin-x86_64]

@deepj deepj changed the title JRuby 9.0.0.0.pre2 starts handing while reading from a socket JRuby 9.0.0.0.pre2 starts hanging while reading from a socket May 19, 2015

@headius

This comment has been minimized.

Copy link
Member

headius commented May 21, 2015

I'll have a look.

@headius headius added the JRuby 9000 label May 21, 2015

@headius

This comment has been minimized.

Copy link
Member

headius commented May 21, 2015

It seems like it's not getting an EOF, or not handling end of data properly. I added some printing to show how much of the response comes back, and it seems to get the full content but does not EOF (which would let the read return):

[] ~/projects/puma $ jruby -Xjit.threshold=0  -Ilib test/test_puma_server.rb -n test_custom_http_codes_10
/Users/headius/projects/jruby/lib/ruby/stdlib/power_assert.rb:7: warning: tracing (e.g. set_trace_func) will not capture all events without --debug flag
Loaded suite test/test_puma_server
Started
HTTP/1.0 449 CUSTOM
Content-Length: 0

^C
@headius

This comment has been minimized.

Copy link
Member

headius commented May 21, 2015

Ok, this is interesting. If I make the content of the response non-empty, it doesn't hang. Something about content-length=0 is causing this.

I suspect there's something preventing the socket from getting closed when content-length=0, and assuming this works ok in MRI it would mean that JRuby's not closing the stream.

@deepj

This comment has been minimized.

Copy link
Author

deepj commented May 21, 2015

I guess it is the last one because it is not hanging on JRuby 1.7 (see https://travis-ci.org/puma/puma/jobs/63112451)

@headius

This comment has been minimized.

Copy link
Member

headius commented May 21, 2015

I think I've found the issue. Because we often (usually) use JDK streams for most types of IO, we have to emulate errno behavior to match C's write(2). My logic there was producing an errno of EAGAIN whenever zero data could be written to a nonblocking stream. However in this case, it's a zero-length write, so it should just report that it wrote 0 rather than marking EAGAIN.

Fix should be coming shortly.

@deepj

This comment has been minimized.

Copy link
Author

deepj commented May 21, 2015

Great, thanks! I hope my catch helped a bit to improve JRuby :)

@headius

This comment has been minimized.

Copy link
Member

headius commented May 21, 2015

@deepj Indeed it did! This is a peculiar edge case we must not have had any test cases for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.