guard / listen

The Listen gem listens to file modifications and notifies you about the changes.
https://rubygems.org/gems/listen
MIT License
1.92k stars 247 forks source link

run() in thread failed: undefined method `callback!' for nil:NilClass on FreeBSD #475

Closed trombik closed 3 years ago

trombik commented 4 years ago

hi,

while trying to use guard, the watcher throws an exception after modifying a watched file.

[1] guard(main)> E, [2020-04-27T06:56:46.488159 #30911] ERROR -- : run() in thread failed: undefined method `callback!' for nil:NilClass:\n /usr/home/trombik/github/trombik/motbot/vendor/bundle/ruby/2.6/gems/rb-kqueue-0.2.5/lib/rb-kqueue/event.rb:80:in `callback!'
/usr/home/trombik/github/trombik/motbot/vendor/bundle/ruby/2.6/gems/rb-kqueue-0.2.5/lib/rb-kqueue/queue.rb:337:in `block in process'
/usr/home/trombik/github/trombik/motbot/vendor/bundle/ruby/2.6/gems/rb-kqueue-0.2.5/lib/rb-kqueue/queue.rb:337:in `each'
/usr/home/trombik/github/trombik/motbot/vendor/bundle/ruby/2.6/gems/rb-kqueue-0.2.5/lib/rb-kqueue/queue.rb:337:in `process'
/usr/home/trombik/github/trombik/motbot/vendor/bundle/ruby/2.6/gems/rb-kqueue-0.2.5/lib/rb-kqueue/queue.rb:316:in `run'
/usr/home/trombik/github/trombik/motbot/vendor/bundle/ruby/2.6/gems/listen-3.2.1/lib/listen/adapter/bsd.rb:50:in `_run'
...

and some specs fails with the same exception when I run the specs in listen.

Failures:

  1) Listen with one listen dir force_polling option to false with default ignore options listens to subdirectory removed listen to the files of a removed directory
     Got 0 failures and 2 other errors:

     1.1) Failure/Error: @worker.run

          NoMethodError:
            undefined method `callback!' for nil:NilClass
          # ./vendor/bundle/ruby/2.6/gems/rb-kqueue-0.2.5/lib/rb-kqueue/event.rb:80:in `callback!'
          # ./vendor/bundle/ruby/2.6/gems/rb-kqueue-0.2.5/lib/rb-kqueue/queue.rb:337:in `block in process'
          # ./vendor/bundle/ruby/2.6/gems/rb-kqueue-0.2.5/lib/rb-kqueue/queue.rb:337:in `each'
          # ./vendor/bundle/ruby/2.6/gems/rb-kqueue-0.2.5/lib/rb-kqueue/queue.rb:337:in `process'
          # ./vendor/bundle/ruby/2.6/gems/rb-kqueue-0.2.5/lib/rb-kqueue/queue.rb:316:in `run'
          # ./lib/listen/adapter/bsd.rb:50:in `_run'
          # ./lib/listen/adapter/base.rb:78:in `block in start'
          # ./lib/listen/internals/thread_pool.rb:6:in `block in add'

     1.2) Failure/Error: @worker.run

          NoMethodError:
            undefined method `callback!' for nil:NilClass
          # ./vendor/bundle/ruby/2.6/gems/rb-kqueue-0.2.5/lib/rb-kqueue/event.rb:80:in `callback!'
          # ./vendor/bundle/ruby/2.6/gems/rb-kqueue-0.2.5/lib/rb-kqueue/queue.rb:337:in `block in process'
          # ./vendor/bundle/ruby/2.6/gems/rb-kqueue-0.2.5/lib/rb-kqueue/queue.rb:337:in `each'
          # ./vendor/bundle/ruby/2.6/gems/rb-kqueue-0.2.5/lib/rb-kqueue/queue.rb:337:in `process'
          # ./vendor/bundle/ruby/2.6/gems/rb-kqueue-0.2.5/lib/rb-kqueue/queue.rb:316:in `run'
          # ./lib/listen/adapter/bsd.rb:50:in `_run'
          # ./lib/listen/adapter/base.rb:78:in `block in start'
          # ./lib/listen/internals/thread_pool.rb:6:in `block in add'

  2) Listen with one listen dir force_polling option to false with default ignore options existing file.rb in listen dir listens to file.rb moved out
     Got 0 failures and 2 other errors:

     2.1) Failure/Error: @worker.run

          NoMethodError:
            undefined method `callback!' for nil:NilClass
...

Finished in 2 minutes 15.6 seconds (files took 0.28346 seconds to load)
322 examples, 6 failures, 1 pending

Failed examples:

rspec './spec/acceptance/listen_spec.rb[1:1:2:2:7:1]' # Listen with one listen dir force_polling option to false with default ignore options listens to subdirectory removed listen to the files of a removed directory
rspec './spec/acceptance/listen_spec.rb[1:1:2:2:2:3]' # Listen with one listen dir force_polling option to false with default ignore options existing file.rb in listen dir listens to file.rb moved out
rspec './spec/acceptance/listen_spec.rb[1:1:2:2:2:2]' # Listen with one listen dir force_polling option to false with default ignore options existing file.rb in listen dir is expected to process removal of "file.rb"
rspec './spec/acceptance/listen_spec.rb[1:1:2:2:6:2]' # Listen with one listen dir force_polling option to false with default ignore options two dirs with files in listen dir listens to dir move
rspec './spec/acceptance/listen_spec.rb[1:1:2:2:6:1]' # Listen with one listen dir force_polling option to false with default ignore options two dirs with files in listen dir listens to multiple file moves
rspec './spec/acceptance/listen_spec.rb[1:1:2:2:5:1]' # Listen with one listen dir force_polling option to false with default ignore options dir with file in listen dir listens to file move
> ruby --version 
ruby 2.6.6p146 (2020-03-31 revision 67876) [amd64-freebsd13]
> uname -msr 
FreeBSD 13.0-CURRENT amd64

as I cannot see any significant change in the bsd adapter, the issue is somewhere else, which is where i am stuck.

gridbugs commented 4 years ago

I'm also running into this.

> ruby --version
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-freebsd12.1]
> uname -msr
FreeBSD 12.1-RELEASE amd64
michelboaventura commented 4 years ago

I'm having the same problem with this configuration:

> uname -msr 
FreeBSD 12.1-RELEASE-p8 amd64
> ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-freebsd12.1]
gridbugs commented 4 years ago

I have a PR open which should fix this: https://github.com/mat813/rb-kqueue/pull/12 Try it out by replacing the rb-kqueue line in your Gemfile with:

gem 'rb-kqueue', :git => "https://github.com/stevebob/rb-kqueue.git", :ref => "144ee7bb7963c77fc219ba736df7ee952d50ab19"
ColinDKelley commented 3 years ago

@stevebob @trombik @michelboaventura Does it look like the fix mentioned in the PR has fixed the problem? https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=250432 Anything we need to change here in listen?

trombik commented 3 years ago

@stevebob @trombik @michelboaventura Does it look like the fix mentioned in the PR has fixed the problem? https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=250432

I haven't tried the mentioned patch because I'm not using listen, thus rb-kqueue, from ports. With bundler, mat813/rb-kqueue#12 fixes the issue. With the patch, all the specs in listen passed.

Anything we need to change here in listen?

No. Adding a "known issue" might help other users, though.

Anyone having the issue: add the following to Gemfile

gem "rb-kqueue", git: "https://github.com/stevebob/rb-kqueue.git", branch: "handle-unexpected-events"
ColinDKelley commented 3 years ago

@trombik I'm happy to add that as a "known issue". Do those go in the README or somewhere else?

trombik commented 3 years ago

Issues / limitations in README.md is the best place, I guess. something like:

FreeBSD users need patched version of rb-kqueue (as of 2020/11). see #475 for the issue, https://github.com/mat813/rb-kqueue/pull/12 for the patch, and Bug 250432 in bugzilla.

ColinDKelley commented 3 years ago

Adding to README here: https://github.com/guard/listen/pull/503/commits/a4c60957f49301a029704ebaee1ffbc2e83f2919

gregschmit commented 3 years ago

FYI, I'm helping out as a maintainer on rb-kqueue; the latest version (0.2.6) includes @stevebob's patch. https://rubygems.org/gems/rb-kqueue

ColinDKelley commented 3 years ago

@gregschmit Do you need anything here in listen, or is your message just an FYI?

gregschmit commented 3 years ago

@ColinDKelley it's just an FYI; I noticed you mentioned this issue in your README so if you want, you can remove that at some point.

ColinDKelley commented 3 years ago

@gregschmit Thanks for the clarification. I'll try to get that reference out of the README soon.

ColinDKelley commented 3 years ago

^ done