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

Code is not reloaded in dev with Docker on OS X #25186

Closed
jeromedalbert opened this issue May 28, 2016 · 15 comments
Closed

Code is not reloaded in dev with Docker on OS X #25186

jeromedalbert opened this issue May 28, 2016 · 15 comments

Comments

@jeromedalbert
Copy link

@jeromedalbert jeromedalbert commented May 28, 2016

Steps to reproduce

  1. Install the Docker toolbox on OS X. Here are my instructions to install it with brew.
  2. Clone https://github.com/jeromedalbert/rails_5_rc1_docker. I have created this dummy application specifically for this issue.
  3. Follow the short instructions to set up the project and have a server running.
  4. Open the application in your browser.
  5. While the server is running, edit app/controllers/static_controller.rb and change 'hello world!' to 'coconut'.
  6. Reload the page in your browser.

Expected behavior

The page should display "coconut".

Actual behavior

The page displays the old "hello world!" text.

System configuration

Rails version: 5.0.0.rc1

Ruby version: 2.3.1

Workaround

To make code reloading work for now, in config/environments/development.rb replace

config.file_watcher = ActiveSupport::EventedFileUpdateChecker

with

config.file_watcher = ActiveSupport::FileUpdateChecker

Restart everything, and code reloading should work.

Additional comments

I have a feeling that for the ActiveSupport::EventedFileUpdateChecker file watcher, the change event does not occur for docker-machine shared files. So it may be more about docker-machine than Rails. But since I am not versed enough in the EventedFileUpdateChecker internals, I cannot say for sure.

Even if it is docker-machine's fault, since I cannot pinpoint the exact problem, I would not know how to articulate it if I were to open an issue on their github repo. We might also find a workaround in Rails or add a warning the Rails documentation. That's why I am opening this issue here. Any insight would be appreciated.

@gsamokovarov
Copy link
Contributor

@gsamokovarov gsamokovarov commented May 28, 2016

The docker on OSX runs on a thin Linux virtual machine. The virtual machine provisioners share code between the VM and the host on a file system that doesn't support notification events, so we cannot use the new listener backend on those.

@fxn
Copy link
Member

@fxn fxn commented May 28, 2016

What @gsamokovarov said.

Some setups do not work because fs events are not triggered. The generator has some simple code to comment out that configuration line.

Do you think the application generator can detect this particular setup somehow?

@jeremy
Copy link
Member

@jeremy jeremy commented May 28, 2016

Note this will(/should) work with the forthcoming Docker for Mac/Windows that are now in beta. OS X FSEvents are bridged to inotify.

@lnikell
Copy link

@lnikell lnikell commented May 29, 2016

I had the same issue with my HyperV Ubuntu 16.04, any changes at controllers, models not affected until restart server. Only css and changes in views work properly

@fxn
Copy link
Member

@fxn fxn commented May 29, 2016

This is something Rails cannot do anything about unless support for detecting this at runtime and hot-switching the monitors is implemented.

Also, you could generate the conservative option always (it was this way when the feature was first implemented). But it was decided to generate the config for the evented monitor by default (mod those simple exceptions linked above) because it is believed that most setups can benefit from it. If the setup does not support it, then you need to opt-out.

I think we can close this one on the basis of not having a bug here, but if you believe Rails could explain this better somewhere please feel free to make a proposal.

@fxn fxn closed this May 29, 2016
@mrkongo
Copy link

@mrkongo mrkongo commented Aug 21, 2016

@fxn:

Also, you could generate the conservative option always

How to?

@fxn
Copy link
Member

@fxn fxn commented Aug 23, 2016

@mrkongo Go to config/environments/development.rb and comment

config.file_watcher = ActiveSupport::EventedFileUpdateChecker

out. If not needed for anything else, you may also want to remove the listen gem dependency in Gemfile.

@krainboltgreene
Copy link
Contributor

@krainboltgreene krainboltgreene commented Feb 14, 2017

For anyone looking at this, Docker For Mac has other file issues that prevent EventedFile from working. Use File and stick to Docker Toolbox.

@f1nnix
Copy link

@f1nnix f1nnix commented Jun 22, 2017

FileUpdateChecker fix doesn't work properly on:

  • docker-machine version 0.11.0, build 5b27455
  • Docker version 17.05.0-ce, build 89658be

After change, code is reloaded with ~5 min lag, which makes code reload feature practically useless. Is there any workaround for this?

Thank you.

@krainboltgreene
Copy link
Contributor

@krainboltgreene krainboltgreene commented Jun 22, 2017

@f1nnix Frankly there never will. You're writing to a file on a computer, that then has to tell some extra file system (Likely vbfs or nfs) of the event, that then has to propagate to the guest machine's filesystem, that then has to report to docker that the file event happened.

Basically, avoid dealing with superhost machine file events.

ztolley added a commit to barnardos/consent-form-builder that referenced this issue Jul 27, 2017
Rails does not play well with docker with due to not supporting events telling ruby a file changed. The docker config tells rails to poll files rather than rely on events.

Tested to not increase CPU usage

rails/rails#25186
knpwrs added a commit to knpwrs/pco-graphql that referenced this issue Aug 13, 2017
@Glutexo
Copy link

@Glutexo Glutexo commented Feb 20, 2018

For me the EventedFileUpdateChecker does not work even on bare macOS without Docker. Switching to FileUpdateChecker solved the issue.

@krainboltgreene
Copy link
Contributor

@krainboltgreene krainboltgreene commented Feb 20, 2018

That's sort of a "known issue" with Mac's file watcher. Some things (say, dropbox) can just take complete control, apparently?

@sn
Copy link

@sn sn commented Sep 11, 2019

Just to add to this issue. If you are running your Rails app within a VirtualBox VM, then you are highly likely to experience this too. It doesn't always happen though so it's very tricky to diagnose properly.

Updates made to views won't reflect until you full restart the Rails server.

To fix the issue:

In environments/development.rb, comment out:
config.file_watcher = ActiveSupport::EventedFileUpdateChecker

Add:
config.file_watcher = ActiveSupport::FileUpdateChecker

Current version of what I'm running (for context):

  • Rails 6.0.0
  • Vagrant 2.2.4
  • VirtualBox 6.0
@nitsujri
Copy link

@nitsujri nitsujri commented Oct 1, 2020

It's probably just my system, but I recently upgraded to Docker Desktop Community 2.4.0.0 for Mac and lost file updates in Docker.

It works fine if I'm running on my host machine (OSX) or if I switch the file_watcher to FileUpdateChecker.

[EDIT]
So, maybe not my system, I downgraded Docker Desktop from 2.4.0.0 => 2.3.0.5 and it started working again using EventedFileUpdateChecker.

@nitsujri
Copy link

@nitsujri nitsujri commented Oct 2, 2020

Opened an issue w/ Docker as well docker/for-mac#4962.

Here's a repo for reproduction w/ instructions: https://github.com/jenfi-eng/docker-rails-reload-issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet