thoughtbot / capybara-webkit

A Capybara driver for headless WebKit to test JavaScript web apps
https://thoughtbot.com/open-source
MIT License
1.97k stars 427 forks source link

AsynchronousCloseException #944

Closed pcsgithubid closed 7 years ago

pcsgithubid commented 8 years ago

the below exception is raised by the feature spec, but feature spec completes successfully.

tech

jruby9000 caybara 2.4.0

caybara-webkit 1.3.0

java.nio.channels.AsynchronousCloseException at java.nio.channels.spi.AbstractInterruptibleChannel.end(AbstractInterruptibleChannel.java:205) at sun.nio.ch.SourceChannelImpl.read(SourceChannelImpl.java:173) at org.jruby.RubyIO.transfer(RubyIO.java:4210) at org.jruby.RubyIO.copy_stream(RubyIO.java:4097) at org.jruby.RubyIO$INVOKER$s$0$2$copy_stream.call(RubyIO$INVOKER$s$0$2$copy_stream.gen) at org.jruby.internal.runtime.methods.JavaMethod$JavaMethodN.call(JavaMethod.java:724) at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:205) at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:358) at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:195) at org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:324) at org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:73) at org.jruby.ir.interpreter.Interpreter.INTERPRET_BLOCK(Interpreter.java:132) at org.jruby.runtime.MixedModeIRBlockBody.commonYieldPath(MixedModeIRBlockBody.java:148) at org.jruby.runtime.IRBlockBody.call(IRBlockBody.java:66) at org.jruby.runtime.Block.call(Block.java:126) at org.jruby.RubyProc.call(RubyProc.java:324) at org.jruby.RubyProc.call(RubyProc.java:248) at org.jruby.internal.runtime.RubyRunnable.run(RubyRunnable.java:104) at java.lang.Thread.run(Thread.java:745)

twalpole commented 8 years ago

That trace only shows java files so gives no info about what (if anything) in capybara/capybara-WebKit is causing this. Additionally the gems you're using are over 2 years old. I'd recommend updating capybara and capybara-webkit, there's been a lot of bug fixes since the versions you're using.

pcsgithubid commented 8 years ago

jruby9000 caybara 2.7.1 caybara-webkit 1.11.1

with above version also i get the same exception. please let me know How to enable trace logs

twalpole commented 8 years ago

No clue -- it's raising an internal ruby exception -- If you can provide a way to reproduce the issue someone can look into it, otherwise there's not much anyone can do.

pjpoole commented 8 years ago

I'm getting the same error. Environment: jruby-9.1.5.0 capybara 2.7.1 capybara-webkit 1.11.1 java version "1.8.0_45" Java(TM) SE Runtime Environment (build 1.8.0_45-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode) Rails 4.2.5

Steps to reproduce:

require 'capybara'
require 'capybara/rails'

Capybara.configure do |config|
  config.default_driver = :webkit
end

class ActionDispatch::IntegrationTest
  include Capybara::DSL
end

class ThingTest < ActionDispatch::IntegrationTest
  test 'thing' do
    visit '/'
  end
end
synth commented 7 years ago

šŸ‘ I'm hitting this as well. Was originally on capybara 1.10.1, and upgraded to 1.11.1 and hit this in both cases. On OSX 10.12.1 (Sierra)

HarlemSquirrel commented 7 years ago

I'm also hitting this with the following versions jruby 9.1.7.0 (2.3.1) 2017-01-11 rails-4.1.16 rspec-rails-3.6.0 capybara-2.13.0 capybara-webkit-1.14.0

twalpole commented 7 years ago

@HarlemSquirrel Can you provide a small reproducible test case (public project on github, etc) that will reproduce this?

HarlemSquirrel commented 7 years ago

@twalpole here you go https://github.com/HarlemSquirrel/jruby-rails-demo

twalpole commented 7 years ago

@HarlemSquirrel Thanks for putting in the effort to produce an immediately reproducible example.

This text is output because the server executable (webkit_server) process isn't explicitly terminated when capybara-webkit shuts down. Killing off the process at exit should be a relatively simple thing, although there are some cross platform issues. Unfortunately the "wait thread" object JRuby returns from popen3 doesn't contain the pid that it does under MRI - so we'd probably have to use IO::popen4 on JRuby which returns the pid directly (but isn't available on MRI - not sure about rubinius). @jferris @mhoran thoughts?

mhoran commented 7 years ago

We used to explicitly terminate webkit_server at_exit, which led to all sorts of other issues (^C^C, for example, wouldn't kill webkit_server processes). We instead switched to an implementation that kills the webkit_server automatically when its stdin is closed. That has worked pretty well, but it seems now that there's a problem with JRuby (there was before as well.) My initial reaction is that this is likely a bug in JRuby, as the behavior works fine across all other Ruby VMs.

twalpole commented 7 years ago

@mhoran It seems like leaving the killing of the process at exception setting, and also explicitly killing it at_exit should be able to coexist, and potentially fix this issue without a downside.

mhoran commented 7 years ago

I'd rather find a way to fix this without an at_exit hook if possible. Even though the additional code is minimal, the fact remains that the at_exit implementation was actually untestable on JRuby, which is the problem platform. So even if we fix this with a hook, we won't be able to verify against regressions.

On May 16, 2017 6:29:39 PM EDT, Thomas Walpole notifications@github.com wrote:

@mhoran It seems like leaving the killing of the process at exception setting, and also explicitly killing it at_exit should be able to coexist, and potentially fix this issue without a downside.

-- You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/thoughtbot/capybara-webkit/issues/944#issuecomment-301933932

-- Sent from my mobile device.

twalpole commented 7 years ago

@mhoran I wrote a test that does test for the condition, and then added back in the explicit killing of webkit_server which fixes the issue (and passes the test). There are other failures in the JRuby 1.9 runs but they exist in master also, and I'm guessing are caused by updates to some gem. PR #1004

mhoran commented 7 years ago

I still don't totally understand what the issue is here, and would like to figure that out before merging this. Maybe someone else will have the chance to review before me.

On May 17, 2017 1:03:04 AM EDT, Thomas Walpole notifications@github.com wrote:

@mhoran I wrote a test that does test for the condition, and then added back in the explicit killing of webkit_server which fixes the issue (and passes the test). There are other failures in the JRuby 1.9 runs but they exist in master also, and I'm guessing are caused by updates to some gem.

-- You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/thoughtbot/capybara-webkit/issues/944#issuecomment-301986187

-- Sent from my mobile device.

twalpole commented 7 years ago

@mhoran The issue is a bunch of extra text output to stderr when tests exit. This happens because a child process (webkit_server) is still running when JRuby goes to exit and it then notifies that it's not cleanly shutting down, since it's having to kill off the subprocess, by reporting an AsynchronousCloseException to stderr. Also, I worked out why the jruby-19mode runs were failing on master, PR #1005 should fix that.

twalpole commented 7 years ago

Fixed in master