Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reloading Issue Triggering Resolved Rails Bug #328

Closed
BintLopez opened this issue Mar 22, 2019 · 16 comments
Closed

Reloading Issue Triggering Resolved Rails Bug #328

BintLopez opened this issue Mar 22, 2019 · 16 comments

Comments

@BintLopez
Copy link

Related Rails issue: rails/rails#32700

Steps to reproduce

  • Creating a new rails project with ruby 2.5.3 and rails 6.0.0.beta3
  • Add gem 'factory_bot_rails', '~> 5.0', '>= 5.0.1' to the gemfile
  • Install gems bundle install
  • boot up the rails server bundle exec rails s
  • view errors in server output

Expected behavior

Adding factory_bot_rails gem to a rails project should not trigger ** ERROR: directory is already being watched! ** when booting up a rails server or console

Actual behavior

After including the gem in my project, I'm getting the following errors in my server when running the rails server...

be rails s
=> Booting Puma
=> Rails 6.0.0.beta3 application starting in development 
=> Run `rails server --help` for more startup options
        ** ERROR: directory is already being watched! **

        Directory: /path/to/my/app/node_modules/.bin/compression-webpack-plugin

        is already being watched through: /path/to/my/app/node_modules/compression-webpack-plugin

        MORE INFO: https://github.com/guard/listen/wiki/Duplicate-directory-errors
        ** ERROR: directory is already being watched! **

        Directory: /path/to/my/app/node_modules/.bin/mini-css-extract-plugin

        is already being watched through: /path/to/my/app/node_modules/mini-css-extract-plugin

        MORE INFO: https://github.com/guard/listen/wiki/Duplicate-directory-errors
(node:33074) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
        ** ERROR: directory is already being watched! **

        Directory: /path/to/my/app/node_modules/@rails/webpacker/node_modules/.bin/compression-webpack-plugin

        is already being watched through: /path/to/my/app/node_modules/compression-webpack-plugin

        MORE INFO: https://github.com/guard/listen/wiki/Duplicate-directory-errors
        ** ERROR: directory is already being watched! **

        Directory: /path/to/my/app/node_modules/@rails/webpacker/node_modules/.bin/mini-css-extract-plugin

        is already being watched through: /path/to/my/app/node_modules/mini-css-extract-plugin

        MORE INFO: https://github.com/guard/listen/wiki/Duplicate-directory-errors
Puma starting in single mode...
* Version 3.12.1 (ruby 2.5.3-p105), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000

System configuration

Rails version: 6.0.0.beta3

Ruby version: 2.5.3

@composerinteralia
Copy link
Collaborator

Hm, this should have been fixed by f718048, which went out in factory_bot_rails 5.0.1

Thanks for the report!

@TeTiRoss
Copy link

TeTiRoss commented Mar 25, 2019

Having the same ERROR: directory is already being watched! when I'm running daemon process with daemons gem. Without factory_bot_rails everything works as expected.

@composerinteralia
Copy link
Collaborator

@TeTiRoss what version of factory_bot_rails are you using?

@TeTiRoss
Copy link

TeTiRoss commented Mar 25, 2019

@composerinteralia
factory_bot_rails 5.0.1
Ruby 2.6.1
Rails 5.2.2.1

@composerinteralia
Copy link
Collaborator

composerinteralia commented Mar 31, 2019

@BintLopez I wasn't able to reproduce this with the steps you provided. Is there something I am missing?

rails new testing
cd testing
echo "gem 'factory_bot_rails', '~> 5.0', '>=5.0.1', group: [:test, :development]" >> Gemfile
bundle install
bin/rails s

I didn't see any error messages. Also, I went into the console and checked that the factory_bot_rails reloader was not actually watching any files (as expected with f718048) :

Rails.application.reloaders.first.send(:directories_to_watch)
#=> []

I am using:
factory_bot_rails 5.0.1
Ruby 2.6.1
Rails 5.2.3


I tried these steps on 6.0.0.beta3 as well and had the same results. I am especially surprised you are seeing this on 6.0.0.beta3, since rails/rails#33822 was included in that release.

@yazumoto
Copy link

yazumoto commented Apr 1, 2019

I also encountered this error on factory_bot 5.0.0, factory_bot_rails: 5.0.0.
But fixed it after updated to factory_bot: 5.0.2, factory_bot_rails: 5.0.1.

@BintLopez
Copy link
Author

I ran through the repro steps with a fresh rails project (using 6.0.0.beta3) and was able to reproduce with both ruby 2.5.3 and ruby 2.6.2. This is using gem 'factory_bot_rails', '~> 5.0', '>=5.0.1.

@composerinteralia
Copy link
Collaborator

composerinteralia commented Apr 1, 2019

@yazumoto that makes sense, since the fix in f718048 went out in factory_bot_rails 5.0.1. Thanks for letting me know!

@BintLopez would you be to share a link to the fresh rails project you used to reproduce this? Thanks for your help!

@BintLopez
Copy link
Author

@composerinteralia -- here's the repo that triggers the error for me: https://github.com/BintLopez/testing_bug_repro.

What I did to reproduce was rails new, add gem 'factory_bot_rails', '~> 5.0', '>=5.0.1 to the Gemfile, bundle, and then run bundle exec rails server. The first commit is initializing the project -- booting up the server does not trigger the error. The second commit adds the gem and that's when errors start for me.

Based on the write up at the link from the error https://github.com/guard/listen/wiki/Duplicate-directory-errors ... this appears to be a bug in how listen handles symlinks. What about factory bot rails is triggering this bug in listen? Or perhaps there's something in my local env contributing to this 🤷‍♀️ ... def interested to see if my repo yields the same errors for you locally.

@composerinteralia
Copy link
Collaborator

@BintLopez unfortunately I still am not seeing the error in your test repo. It seems like we are following exactly the same steps, so I am not sure what is different.

I would be curious to know what you get if you start a rails console and type: Rails.application.reloaders.first.send(:directories_to_watch)

@BintLopez
Copy link
Author

Thanks for that command! Running that returns an empty array. But looking at it for all the reloaders returned the following...

Rails.application.reloaders.map{|r| r.send(:directories_to_watch) if r.respond_to?(:directories_to_watch, true)}
=> [
        [],
        [#<Pathname:/Users/path/to/my/project/config/locales>],
        nil,
        [#<Pathname:/Users/path/to/my/project/db>,
         #<Pathname:Users/path/to/my/project/app/channels>,
         #<Pathname:/Users/path/to/my/project/app/controllers>, 
         #<Pathname:/Users/path/to/my/project/app/helpers>, 
         #<Pathname:/Users/path/to/my/project/app/jobs>, 
         #<Pathname:/Users/path/to/my/project/app/mailers>, 
         #<Pathname:/Users/path/to/my/project/app/models>, 
         #<Pathname:/Users/path/to/my/project/test/mailers/previews>]
]

^^ I don't see anything in there that would be loading the js (at first glance)

Also, another data point -- a friend of mine ran the same code and was not able to reproduce the same issue. This makes me think it's something about dev env that's in the works here. I use rbenv for ruby version, nvm for node versioning, homebrew (maybe brew has something to do since it's symlinks?). Running in a mac os. At any rate, this isn't a blocker for me, and shouldn't affect production since listen is only included in dev environment. Just very noisy console output 🙉 . Likely going to do the monkey patch suggested here as a workaround -- https://github.com/guard/listen/wiki/Duplicate-directory-errors#monkey-patch

@composerinteralia
Copy link
Collaborator

composerinteralia commented Apr 3, 2019

That reloader output looks right to me:

  • [] This is the factory_bot_rails reloader. It is not watching any directories. That is expected since there aren't any factory_bot definition files yet
  • Next is the I18n reloader, which is watching the locales directory
  • Then the routes reloader, which uses its own Rails::Application::RoutesReloader that doesn't have the private directories_to_watch method
  • Finally the main application loader for you models, controllers, etc.

I am stumped. Let me know if that patch helps and maybe we can work backwards from there.

@composerinteralia
Copy link
Collaborator

@y-yagi do you have any ideas about what might be going on here?

@y-yagi
Copy link
Contributor

y-yagi commented Apr 4, 2019

Thank you for the mention. I think this is an issue of Rails.

I will fix this on Rails side first. But considering the old Rails version, I think it would be better to fix the factory_bot_rails side as well.

@composerinteralia I think it's better not to call FactoryBot.reload if there is no file or directory to watch. What do you think?

@composerinteralia
Copy link
Collaborator

Aha! That makes sense. Thanks so much for your help. Yeah, I agree we should fix it on the factory_bot_rails side as well. There is no need to reload if no files or directories exist!

@y-yagi
Copy link
Contributor

y-yagi commented Apr 4, 2019

👍 I will create a PR later.

y-yagi added a commit to y-yagi/factory_bot_rails that referenced this issue Apr 4, 2019
If all the paths specified in `FactoryBot.definition_file_paths` do not
exist, an empty array is passed to the reloader.

If an empty array is specified, reloader passes it to `Listen.to` as it
is. This causes the application root to be watched and `node_modules` to
become a target of listening.

The behavior when an empty array is passed to reloader depends on the
Rails side. Fixes to not register a reloader when file paths do not exist
consistent behavior regardless of Rails side.

Fixes thoughtbot#328.
y-yagi added a commit to y-yagi/factory_bot_rails that referenced this issue Apr 5, 2019
If all the paths specified in `FactoryBot.definition_file_paths` do not
exist, an empty array is passed to the reloader.

If an empty array is specified, reloader passes it to `Listen.to` as it
is. This causes the application root to be watched and `node_modules` to
become a target of listening.

The behavior when an empty array is passed to reloader depends on the
Rails side. Fixes to not register a reloader when file paths do not exist
consistent behavior regardless of Rails side.

Fixes thoughtbot#328.
y-yagi added a commit to y-yagi/factory_bot_rails that referenced this issue Apr 9, 2019
If all the paths specified in `FactoryBot.definition_file_paths` do not
exist, an empty array is passed to the reloader.

If an empty array is specified, reloader passes it to `Listen.to` as it
is. This causes the application root to be watched and `node_modules` to
become a target of listening.

The behavior when an empty array is passed to reloader depends on the
Rails side. Fixes to not register a reloader when file paths do not exist
consistent behavior regardless of Rails side.

Fixes thoughtbot#328.
composerinteralia pushed a commit that referenced this issue Apr 9, 2019
If all the paths specified in `FactoryBot.definition_file_paths` do not
exist, an empty array is passed to the reloader.

If an empty array is specified, reloader passes it to `Listen.to` as it
is. This causes the application root to be watched and `node_modules` to
become a target of listening.

The behavior when an empty array is passed to reloader depends on the
Rails side. Fixes to not register a reloader when file paths do not exist
consistent behavior regardless of Rails side.

Fixes #328.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants