Open
Description
Your environment
ruby -v:ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [arm64-darwin20]rdbg -v:rdbg 1.3.1(f5ff7f7)- OS: macOS 11.6 20G165
Describe the bug
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).
To Reproduce
I prepare a repository for reproduction. Please follow the instruction on the README:
https://github.com/ybiquitous/ruby-debug-with-capybara
Screen.Recording.2021-10-23.at.13.29.49.mov
Note: Here is a simplified version on Gist (thanks to @nishio-dens):
https://gist.github.com/nishio-dens/c64245eb143e9c3b22b9d7b9f93f25d2
Expected behavior
I think Chrome should not hang.
Additional context
None.
Reacted by FURUKAWA,Daisuke and Felix Wolfsteller
Metadata
Metadata
Assignees
Labels
No labels
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)