You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running Capybara and RSpec with Chrome under a certain condition, Chrome hangs.
This never occurs with the child / parent fork mode. It occurs only with the both fork mode (default).
Spent hours debugging why starting multiple browsers (Chrome or Firefox) with Capybara failed to close them all (it only ever closed the last one created). Turned out it was the #at_exit call here:
So when these were called in reverse order of creation, it would clean up the latest browser then hit the #at_exit created from #after_fork_parent and block forever. It would never make it to the next browser to clean it up.
Finally found this issue and after setting the environment variable RUBY_DEBUG_FORK_MODE=parent it all works.
Adding the debug gem broke my Capybara setup (rspec would never exit), but as some other people mentioned running my specs with RUBY_DEBUG_FORK_MODE=parent bin/rspec solved it.
Not sure whether this is an issue with debug or Capybara, but would be great to get it resolved so everything works out-of-the-box without requiring ENV vars.
Hi @ko1 👋
Long time no see! I found myself looking at a very similar situation when running rspec tests with Capybara today. The rspec process never completes. The main thread is hung up on the local.rb line that you referenced above:
/Users/.../ruby/3.1.1/lib/ruby/gems/3.1.0/gems/debug-1.6.1/lib/debug/local.rb:101:in `waitpid'
/Users/.../ruby/3.1.1/lib/ruby/gems/3.1.0/gems/debug-1.6.1/lib/debug/local.rb:101:in `block in after_fork_parent'
The spec forked twice (Once for a capybara server and once to run an external pdflatex command.):
DEBUGGER: Attaching after process 5803 fork to child process 6425
DEBUGGER[/Users/.../ruby/3.1.1/bin/rspec#6460]: Attaching after process 5803 fork to child process 6460
Things work well if the spec only forks once.
I'm happy to provide additional details if they help to narrow down the problem.
My first attempts in making a reproduction were not successful. It's very possible that I'm missing a detail that triggers the condition in our main codebase. There are a lot of moving parts and layers involved that could make a difference.
I'll try a bit more but I'm not sure I'll be able to isolate the behavior.
If any tests driven by this driver run then rspec fails to exit. Interestingly tests driven by the standard selenium_chrome_headless driver don't have this problem.
I currently have DEBUGGER__::CONFIG[:fork_mode] = :parent at the top of my config file and that seems to have solved the problem.
Activity
ko1 commentedon Oct 25, 2021
OMG: "Failed to find Chrome binary."
my WSL2 environment it's difficult...
without chrome (with REPL), do you have same trouble?
ybiquitous commentedon Oct 25, 2021
No, this problem occurs with Capybara and Chrome (also headless mode).
Oh, I can reproduce it with macOS. The
webdriversgem's instruction might help you, but it seems limited...https://github.com/titusfortner/webdrivers#wslv2-support
ko1 commentedon Oct 25, 2021
Thank you for the information.
@ono-max san can you try it?
ybiquitous commentedon Nov 4, 2021
Temporarily, is there a way to stop the
debugserver only when starting Capybara?ko1 commentedon Nov 5, 2021
Unfortunately, there is no way to disable debugger now. I'll consider.
Instead of disabling the debugger, you can choose child or parent debug mode (maybe parent mode is fine for you).
On the debugger REPL:
On the Ruby code:
ybiquitous commentedon Nov 5, 2021
@ko1 Thank you for the helpful advice! The workaround works. 👍🏼
FYI. The following code via
ENValso works:nickjer commentedon Nov 14, 2021
Spent hours debugging why starting multiple browsers (Chrome or Firefox) with Capybara failed to close them all (it only ever closed the last one created). Turned out it was the
#at_exitcall here:debug/lib/debug/local.rb
Lines 93 to 105 in 3b3ce8f
Everytime Capybara forked off a new browser it would register a new
#at_exitto clean itself up here:https://github.com/teamcapybara/capybara/blob/a12915a6ae6faf1f79445ccd9e2b29d4c3850d7a/lib/capybara/selenium/driver.rb#L509-L514
So when these were called in reverse order of creation, it would clean up the latest browser then hit the
#at_exitcreated from#after_fork_parentand block forever. It would never make it to the next browser to clean it up.Finally found this issue and after setting the environment variable
RUBY_DEBUG_FORK_MODE=parentit all works.Capybara has issues
marckohlbrugge commentedon Jun 30, 2022
Adding the
debuggem broke my Capybara setup (rspec would never exit), but as some other people mentioned running my specs withRUBY_DEBUG_FORK_MODE=parent bin/rspecsolved it.Not sure whether this is an issue with debug or Capybara, but would be great to get it resolved so everything works out-of-the-box without requiring ENV vars.
ko1 commentedon Jul 5, 2022
Thank you for heading up.
Can you confirm that the process is hung around https://github.com/ruby/debug/blob/master/lib/debug/local.rb#L101 ?
senny commentedon Sep 14, 2022
Hi @ko1 👋
Long time no see! I found myself looking at a very similar situation when running rspec tests with Capybara today. The
rspecprocess never completes. The main thread is hung up on thelocal.rbline that you referenced above:The spec forked twice (Once for a capybara server and once to run an external
pdflatexcommand.):Things work well if the spec only forks once.
I'm happy to provide additional details if they help to narrow down the problem.
ko1 commentedon Sep 16, 2022
Thank you, could you make a small repro-code?
senny commentedon Sep 19, 2022
My first attempts in making a reproduction were not successful. It's very possible that I'm missing a detail that triggers the condition in our main codebase. There are a lot of moving parts and layers involved that could make a difference.
I'll try a bit more but I'm not sure I'll be able to isolate the behavior.
rbclark commentedon Sep 22, 2022
I am seeing the same behavior with Capybara + RSpec + selenium at the moment. In my case I am registering a custom chrome driver:
If any tests driven by this driver run then rspec fails to exit. Interestingly tests driven by the standard
selenium_chrome_headlessdriver don't have this problem.I currently have
DEBUGGER__::CONFIG[:fork_mode] = :parentat the top of my config file and that seems to have solved the problem.Use `exit!` instead of `exit`
Use `exit!` instead of `exit` (#602)