Skip to content

visit(url) hangs on Jruby #197

duelinmarkers opened this Issue Oct 24, 2011 · 8 comments

4 participants


It looks to me like this is a Jruby issue, but it seemed worth raising so at least capybara-webkit users will know about it.

When we call visit (or any browser command with an empty response) we're seeing the browser block when it tries to read the response. Cutting capybara-webkit out of the picture, it appears Jruby's TCPSocket blocks when there's nothing to read, even when the argument to read is zero. MRI returns an empty string immediately.

We have a workaround for this in our fork here: intentmedia/capybara-webkit@73100d7

Tested with Jruby 1.6.3 and 1.6.4 with
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03-384-10M3425)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-384, mixed mode)

on OS X 10.6.8


I've opened in hopes the Jruby team can address this so the workaround isn't needed.

sobrinho commented Nov 8, 2011

Same happens here using jruby 1.6.5.

Using the proposed patch by @duelinmarkers it works!

Maybe this should be here waiting jruby to fix that?

dnagir commented Nov 29, 2011

Have the same issue here (jruby 1.6.5).

The patch actually does make sense: read only when there is something to read. What's the point of reading otherwise?
I don't see why it can't be merged in.

I've send the PR with the changes by @duelinmarkers.
It definitely works for me.


dnagir beat me to it. The pull request is #220.

@derekprior derekprior added a commit to derekprior/capybara-webkit that referenced this issue Mar 30, 2012
@derekprior derekprior Read from socket only when there's content
This works around an issue with the TCPSocket class in jruby that causes
it to block indefinitely while trying to read a non-existent response.
MRI will immediately return an empty string.

The fix was to a private method and required stubbing an instance
variable not publically accessible so the specs have to get kind of cute
to work around this.

This pull request closes issue #197 and supersedes pull request #220
(which had broken specs). Credit @duelinmarkers.
thoughtbot, inc. member

@jferris and I merged in a fix to this on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.