ranmocy / guard-rails

Guard-Rails is watching on your development servers as you wish!
http://ranmocy.github.com/guard-rails
MIT License
137 stars 25 forks source link

Exception when running guard ThreadError: can't be called from trap context #34

Closed nadeemkhedr closed 10 years ago

nadeemkhedr commented 10 years ago

I originally posted an issue on the guard project but I guess the issue is from guard-rails https://github.com/guard/guard/issues/653

The stack trace from running guard. (This suddenly happened today, this setup was working for 2+ months)

14:06:33 - DEBUG - Command execution: which notify-send
14:06:33 - DEBUG - Command execution: emacsclient --eval '1' 2> /dev/null || echo 'N/A'
14:06:33 - INFO - Guard is using NotifySend to send notifications.
14:06:33 - INFO - Guard is using Tmux to send notifications.
14:06:33 - DEBUG - Command execution: tmux list-clients -F '#{client_tty}'
14:06:34 - DEBUG - Command execution: tmux list-clients -F '#{client_tty}'
14:06:34 - DEBUG - Command execution: tmux show -t /dev/pts/0
14:06:34 - INFO - Guard is using TerminalTitle to send notifications.
14:06:34 - DEBUG - Guard starts all plugins
14:06:34 - DEBUG - Hook :start_begin executed for Guard::Bundler
14:06:34 - DEBUG - Command execution: bundle check
14:06:34 - INFO - Bundle already up-to-date
14:06:34 - DEBUG - Hook :start_end executed for Guard::Bundler
14:06:34 - DEBUG - Hook :start_begin executed for Guard::Rails
14:06:34 - INFO - [Guard::Rails] will start the default web server on port 4040 in development.
14:06:34 - INFO - Starting Rails...
14:06:34 - DEBUG - Command execution: notify-send Starting Rails... Rails starting on port 4040 in development... -t 3000 -h int:transient:1 -i /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/$mages/pending.png -u low
14:06:34 - DEBUG - Command execution: tmux -V
14:06:34 - DEBUG - Command execution: tmux set -q status-left-bg yellow 

14:06:34 - ERROR - Guard::Rails failed to achieve its <start>, exception was:
> [#D5BB6C4DB1EE] ThreadError: can't be called from trap context
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:105:in `synchronize'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:105:in `within_preserved_state'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:39:in `stop'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/setuper.rb:219:in `block in _setup_signal_traps'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:55:in `call'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:55:in `pid_file'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:114:in `has_pid?'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:145:in `block in wait_for_no_pid'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:157:in `wait_for_pid_loop'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:145:in `wait_for_no_pid'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:24:in `stop'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:33:in `restart'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails.rb:44:in `reload'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails.rb:37:in `start'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:74:in `block in run_supervised_task'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:71:in `catch'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:71:in `run_supervised_task'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:22:in `block (2 levels) in run'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:150:in `block (3 levels) in _scoped_plugins'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:148:in `each'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:148:in `block (2 levels) in _scoped_plugins'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:147:in `catch'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:147:in `block in _scoped_plugins'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:145:in `each'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:145:in `_scoped_plugins'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:21:in `block in run'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/lumberjack-1.0.9/lib/lumberjack.rb:32:in `unit_of_work'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:20:in `run'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:28:in `block in start'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:108:in `block in within_preserved_state'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:105:in `synchronize'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:105:in `within_preserved_state'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:26:in `start'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/cli.rb:107:in `start'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/bin/guard:6:in `<top (required)>'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/bin/guard:23:in `load'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/bin/guard:23:in `<main>'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/bin/ruby_executable_hooks:15:in `eval'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/bin/ruby_executable_hooks:15:in `<main>'
14:06:34 - INFO - Guard::Rails has just been fired
14:06:34 - DEBUG - Hook :start_begin executed for Guard::RSpec
14:06:34 - INFO - Guard::RSpec is running
14:06:34 - DEBUG - Hook :start_end executed for Guard::RSpec
14:06:34 - INFO - Guard is now watching at '/home/nadeem/work/app/server'

GuardFile

# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard :bundler do
  watch('Gemfile')
  # Uncomment next line if your Gemfile contains the `gemspec' command.
  # watch(/^.+\.gemspec/)
end

guard 'rails', :port => 4040 do
  watch('Gemfile.lock')
  watch(%r{^(config|lib)/.*})
end

# Note: The cmd option is now required due to the increasing number of ways
#       rspec may be run, below are examples of the most common uses.
#  * bundler: 'bundle exec rspec'
#  * bundler binstubs: 'bin/rspec'
#  * spring: 'bin/rsspec' (This will use spring if running and you have
#                          installed the spring binstubs per the docs)
#  * zeus: 'zeus rspec' (requires the server to be started separetly)
#  * 'just' rspec: 'rspec'
guard :rspec, cmd: 'bundle exec rspec' do
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch('spec/spec_helper.rb')  { "spec" }

  # Rails example
  watch(%r{^app/(.+)\.rb$})                           { |m| "spec/#{m[1]}_spec.rb" }
  watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$})          { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
  watch(%r{^app/controllers/(.+)_(controller)\.rb$})  { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
  watch(%r{^spec/support/(.+)\.rb$})                  { "spec" }
  watch('config/routes.rb')                           { "spec/routing" }
  watch('app/controllers/application_controller.rb')  { "spec/controllers" }
  watch('spec/rails_helper.rb')                       { "spec" }

  # Capybara features specs
  watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$})     { |m| "spec/features/#{m[1]}_spec.rb" }

  # Turnip features and steps
  watch(%r{^spec/acceptance/(.+)\.feature$})
  watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$})   { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end

Gemfile.lock

    guard (2.6.1)
      formatador (>= 0.2.4)
      listen (~> 2.7)
      lumberjack (~> 1.0)
      pry (>= 0.9.12)
      thor (>= 0.18.1)
    guard-bundler (2.0.0)
      bundler (~> 1.0)
      guard (~> 2.2)
    guard-rails (0.6.0)
      guard (~> 2.0)
    guard-rspec (4.3.1)
      guard (~> 2.1)
      rspec (>= 2.14, < 4.0)
ranmocy commented 10 years ago

Can you try to get the latest version of RVM by rvm get stable, remove guard-bundler and guard-rspec from both your Gemfile and Guardfile, and then run bundle exec guard -d -p -i -n f again? Just make sure it's not caused by other gems.

If the situation doesn't change, please try to modify your local file /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:55 as @e2 mentioned on guard/guard#653, and run bundle exec guard -d -p -i -n f.

def pid_file
  File.expand_path(options[:pid_file] || File.join(@root, "tmp/pids/#{options[:environment]}.pid"))
rescue
  STDERR.puts "ERROR: pid_file failed with: #{$!.inspect} (#{[@root, @options].inspect})"
  fail
end

Thank you.

P.S. One thing confused me:

> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:55:in `call'
> [#D5BB6C4DB1EE] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:55:in `pid_file'

Since there is no block call in pid_file function.

ranmocy commented 10 years ago

I tested Guard-Rails with 0.6.0 and Guard both 0.6.1 and 0.7.1 on a new Rails project. They both work fine.

e2 commented 10 years ago

@ranmocy - yes, the call baffled me as well.

Also,

guard/setuper.rb:219:in `block in _setup_signal_traps'

... means Interrupt was raised (usually through Ctrl-C).

This explains why there's no error in newer versions of Guard (> 2.6.0) (https://github.com/guard/guard/issues/653#issuecomment-61251359) - because it thinks the user pressed Ctrl-C inside the Pry console (which does nothing when the console isn't active).

If that was not due to the user pressing Ctr-C, then to catch it we'd have to try:

def pid_file
  File.expand_path(options[:pid_file] || File.join(@root, "tmp/pids/#{options[:environment]}.pid"))
rescue Exception
  STDERR.puts "ERROR: pid_file failed: #{$!.inspect} (#{[@root, @options].inspect}), backtrace: \n\t#{$@.join("\n\t")}"
  fail
end

Also, since pid_file is not memiozed, it's called many times in remove_pid_file_and_wait_for_no_pid (I think it's worth patching this).

So it's statistically likely that pressing Ctrl-C will cause the above error almost every time (and this might explain the call - it' might be Ruby's internal block or exception handler, I'm not sure).

@nadeemkhedr - did you press Ctrl-C yourself while Rails was loading?

nadeemkhedr commented 10 years ago

@e2 nope I didn't , i'll try now everything above and post the result

nadeemkhedr commented 10 years ago

@ranmocy I updated rvm & removed guard-spec & guard-bundler, didn't fix

when i am putting the print in the rescue block its not being called (I tried changing other code in the same file and the changes works so I am modifying the right file)

There is another issue when i run guard there are two different error callstack that could happen (randomly)

One of them is the one I posted and the other is this one

13:13:23 - INFO - Guard is using NotifySend to send notifications.
13:13:23 - INFO - Guard is using Tmux to send notifications.
13:13:23 - INFO - Guard is using TerminalTitle to send notifications.
13:13:23 - INFO - [Guard::Rails] will start the default web server on port 4040 in development.
13:13:23 - INFO - Starting Rails...

13:13:23 - ERROR - Guard::Rails failed to achieve its <start>, exception was:
> [#D105EDBAA349] ThreadError: can't be called from trap context
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:105:in `synchronize'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:105:in `within_preserved_state'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:39:in `stop'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/setuper.rb:219:in `block in _setup_signal_traps'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:117:in `call'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:117:in `has_pid?'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:148:in `block in wait_for_no_pid'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:160:in `wait_for_pid_loop'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:148:in `wait_for_no_pid'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:24:in `stop'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:33:in `restart'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails.rb:44:in `reload'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails.rb:37:in `start'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:74:in `block in run_supervised_task'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:71:in `catch'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:71:in `run_supervised_task'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:22:in `block (2 levels) in run'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:150:in `block (3 levels) in _scoped_plugins'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:148:in `each'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:148:in `block (2 levels) in _scoped_plugins'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:147:in `catch'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:147:in `block in _scoped_plugins'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:145:in `each'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:145:in `_scoped_plugins'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:21:in `block in run'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/lumberjack-1.0.9/lib/lumberjack.rb:32:in `unit_of_work'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:20:in `run'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:28:in `block in start'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:108:in `block in within_preserved_state'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:105:in `synchronize'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:105:in `within_preserved_state'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:26:in `start'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/cli.rb:107:in `start'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/bin/guard:6:in `<top (required)>'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/bin/guard:23:in `load'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/bin/guard:23:in `<main>'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/bin/ruby_executable_hooks:15:in `eval'
> [#D105EDBAA349] /home/nadeem/.rvm/gems/ruby-2.1.2@app/bin/ruby_executable_hooks:15:in `<main>'
13:13:23 - INFO - Guard::Rails has just been fired
13:13:23 - INFO - Guard is now watching at '/home/nadeem/work/app/server'

All my tries I left the modified rescue code and it never was called


If i did this

def pid_file
  STDERR.puts "ERROR: pid_file failed: #{$!.inspect} (#{[@root, @options].inspect})}"
  File.expand_path(options[:pid_file] || File.join(@root, "tmp/pids/#{options[:environment]}.pid"))
end

the callstack is:

server [master●] % guard
13:21:05 - INFO - Guard is using NotifySend to send notifications.
13:21:05 - INFO - Guard is using Tmux to send notifications.
13:21:05 - INFO - Guard is using TerminalTitle to send notifications.
13:21:05 - INFO - [Guard::Rails] will start the default web server on port 4040 in development.
13:21:05 - INFO - Starting Rails...

ERROR: pid_file failed: nil (["/home/nadeem/work/app/server", {:CLI=>nil, :daemon=>false, :debugger=>false, :environment=>"development", :force_run=>false, :pid_fil$
=>nil, :port=>4040, :server=>nil, :start_on_start=>true, :timeout=>30, :zeus_plan=>"server", :zeus=>false}])}
ERROR: pid_file failed: nil (["/home/nadeem/work/app/server", {:CLI=>nil, :daemon=>false, :debugger=>false, :environment=>"development", :force_run=>false, :pid_fil$
=>nil, :port=>4040, :server=>nil, :start_on_start=>true, :timeout=>30, :zeus_plan=>"server", :zeus=>false}])}
13:21:05 - ERROR - Guard::Rails failed to achieve its <start>, exception was:
> [#FA49A8F3E7E5] ThreadError: can't be called from trap context
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:105:in `synchronize'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:105:in `within_preserved_state'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:39:in `stop'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/setuper.rb:219:in `block in _setup_signal_traps'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:55:in `call'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:55:in `inspect'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:55:in `pid_file'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:115:in `has_pid?'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:146:in `block in wait_for_no_pid'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:158:in `wait_for_pid_loop'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:146:in `wait_for_no_pid'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:24:in `stop'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:33:in `restart'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails.rb:44:in `reload'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails.rb:37:in `start'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:74:in `block in run_supervised_task'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:71:in `catch'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:71:in `run_supervised_task'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:22:in `block (2 levels) in run'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:150:in `block (3 levels) in _scoped_plugins'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:148:in `each'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:148:in `block (2 levels) in _scoped_plugins'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:147:in `catch'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:147:in `block in _scoped_plugins'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:145:in `each'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:145:in `_scoped_plugins'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:21:in `block in run'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/lumberjack-1.0.9/lib/lumberjack.rb:32:in `unit_of_work'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:20:in `run'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:28:in `block in start'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:108:in `block in within_preserved_state'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:105:in `synchronize'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:105:in `within_preserved_state'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:26:in `start'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/cli.rb:107:in `start'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/bin/guard:6:in `<top (required)>'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/bin/guard:23:in `load'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/bin/guard:23:in `<main>'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/bin/ruby_executable_hooks:15:in `eval'
> [#FA49A8F3E7E5] /home/nadeem/.rvm/gems/ruby-2.1.2@app/bin/ruby_executable_hooks:15:in `<main>'
13:21:05 - INFO - Guard::Rails has just been fired
13:21:05 - INFO - Guard is now watching at '/home/nadeem/work/app/server'
e2 commented 10 years ago

Looks like guard-rails is somehow interrupting itself:

https://github.com/ranmocy/guard-rails/blob/master/lib/guard/rails/runner.rb#L24

e2 commented 10 years ago

The question is: why is the pid of the ruby/guard process the same as that of the Rails instance?

e2 commented 10 years ago

You could try adding a line to the stop() method:

def stop
  if has_pid?
    pid = File.read(pid_file).strip.to_i
    STDERR.puts "STOPPING: #{pid} (file: #{pid_file}) from process: #{$$}"
    sig_sent = kill_process("INT", pid)
    wait_for_no_pid if sig_sent

    # If you lost your pid_file, you are already died.
    kill_process("KILL", pid)
    remove_pid_file_and_wait_for_no_pid
  end
end
nadeemkhedr commented 10 years ago

Output STOPPING: 0 (file: /home/nadeem/work/app/server/tmp/pids/development.pid) from process: 3229

Full stacktrace

14:18:07 - INFO - Guard is using NotifySend to send notifications.
14:18:07 - INFO - Guard is using Tmux to send notifications.
14:18:07 - INFO - Guard is using TerminalTitle to send notifications.
14:18:07 - INFO - [Guard::Rails] will start the default web server on port 4040 in development.
14:18:07 - INFO - Starting Rails...

STOPPING: 0 (file: /home/nadeem/work/app/server/tmp/pids/development.pid) from process: 3229                                                                   [4/13]
14:18:07 - ERROR - Guard::Rails failed to achieve its <start>, exception was:
> [#F1BAFF26B88E] ThreadError: can't be called from trap context
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:105:in `synchronize'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:105:in `within_preserved_state'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:39:in `stop'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/setuper.rb:219:in `block in _setup_signal_traps'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:56:in `call'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:56:in `pid_file'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:115:in `has_pid?'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:146:in `block in wait_for_no_pid'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:158:in `wait_for_pid_loop'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:146:in `wait_for_no_pid'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:25:in `stop'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails/runner.rb:34:in `restart'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails.rb:44:in `reload'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-rails-0.6.0/lib/guard/rails.rb:37:in `start'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:74:in `block in run_supervised_task'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:71:in `catch'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:71:in `run_supervised_task'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:22:in `block (2 levels) in run'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:150:in `block (3 levels) in _scoped_plugins'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:148:in `each'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:148:in `block (2 levels) in _scoped_plugins'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:147:in `catch'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:147:in `block in _scoped_plugins'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:145:in `each'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:145:in `_scoped_plugins'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:21:in `block in run'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/lumberjack-1.0.9/lib/lumberjack.rb:32:in `unit_of_work'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/runner.rb:20:in `run'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:28:in `block in start'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:108:in `block in within_preserved_state'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:105:in `synchronize'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:105:in `within_preserved_state'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/commander.rb:26:in `start'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/lib/guard/cli.rb:107:in `start'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/gems/guard-2.6.1/bin/guard:6:in `<top (required)>'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/bin/guard:23:in `load'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/bin/guard:23:in `<main>'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/bin/ruby_executable_hooks:15:in `eval'
> [#F1BAFF26B88E] /home/nadeem/.rvm/gems/ruby-2.1.2@app/bin/ruby_executable_hooks:15:in `<main>'
14:18:07 - INFO - Guard::Rails has just been fired
14:18:07 - INFO - Guard is now watching at '/home/nadeem/work/app/server'
e2 commented 10 years ago

check your pid file: /home/nadeem/work/app/server/tmp/pids/development.pid, because I'm guessing it's empty ...

e2 commented 10 years ago

How to reproduce: just create an empty tmp/pids/development.pid

nadeemkhedr commented 10 years ago

@e2 actually there is an empty development.pid there :(

EDIT: it worked after i deleted it , have any clue why that happened ? (it was an empty development.pid)

nadeemkhedr commented 10 years ago

Many thanks guys for solving my problem, now everything is working

e2 commented 10 years ago

@nadeemkhedr - thanks for the detailed reports and for poking around!

ranmocy commented 10 years ago

Thanks guys for pointing out the problem and the pull request from @e2 !

e2 commented 10 years ago

@ranmocy - you're welcome :)