railsjazz / rails_live_reload

Live Reload for your Rails app. The easiest way to increase your productivity.
https://www.railsjazz.com/
MIT License
318 stars 8 forks source link

Issue with rails_live_reload on server startup for Rails 7.0.4.3 #24

Closed TCCDevelopment closed 1 year ago

TCCDevelopment commented 1 year ago

Environment ruby (3.2.1) ruby (7.0.4.3) rails_live_reload (0.3.3)

What happens

When I load the server I get this:

=> Booting Puma
=> Rails 7.0.4.3 application starting in development 
=> Run `bin/rails server --help` for more startup options
Watching: /Users/topher/Library/CloudStorage/Dropbox/TCC-TechDevelopment/Rails/testingNewCreator
  (?-mix:app\/views\/.+\.(erb|haml|slim)$) => on_change
  (?-mix:(app|vendor)\/(assets|javascript)\/\w+\/(.+\.(css|js|html|png|jpg|ts|jsx)).*) => always
#<Thread:0x000000010cef26c8 /Users/topher/.rvm/gems/ruby-3.2.1/gems/rails_live_reload-0.3.3/lib/rails_live_reload/watcher.rb:59 run> terminated with exception (report_on_exception is true):
/Users/topher/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/socket.rb:1119:in `unix': too long unix socket path (121 bytes given but 104 bytes max) (ArgumentError)

    s = Addrinfo.unix(path).listen
                      ^^^^
        from /Users/topher/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/socket.rb:1119:in `unix_server_socket'
        from /Users/topher/.rvm/gems/ruby-3.2.1/gems/rails_live_reload-0.3.3/lib/rails_live_reload/watcher.rb:60:in `block in start_socket'
Puma starting in single mode...
* Puma version: 5.6.5 (ruby 3.2.1-p31) ("Birdie's Version")
*  Min threads: 5
*  Max threads: 5
*  Environment: development
*          PID: 22219
* Listening on ssl://127.0.0.1:3000?key=localhost.key&cert=localhost.crt
* Listening on ssl://[::1]:3000?key=localhost.key&cert=localhost.crt
Use Ctrl-C to stop
Started GET "/" for ::1 at 2023-04-13 13:19:17 -0700
Processing by PagesController#show as HTML
  Parameters: {"page"=>"home"}
  Rendering layout layouts/application.html.erb
  Rendering pages/home.html.erb within layouts/application
  Rendered pages/home.html.erb within layouts/application (Duration: 1.4ms | Allocations: 629)
  Rendered shared/_footer.html.erb (Duration: 1.3ms | Allocations: 1482)
  Rendered shared/_page_bottom_code.html.erb (Duration: 0.6ms | Allocations: 370)
  Rendered layouts/_basic_page.html.erb (Duration: 3.4ms | Allocations: 2759)
  Rendered layout layouts/application.html.erb (Duration: 83.2ms | Allocations: 58604)
Completed 200 OK in 89ms (Views: 86.3ms | ActiveRecord: 0.0ms | Allocations: 61977)

The server still continues to boot but looks like without live_reload. And in the browser I get this error:

script:6 WebSocket connection to 'wss://localhost:3000/rails/live/reload' failed:

I am guessing the browser error is because rails_live_reload was terminated during server startup.

What I tried to fix it

I thought maybe this might be with the initializer config/initializers/rails_live_reload.rb so I deleted that file. That did not solve the issue.

I thought maybe it was due to me using an SSL local environment, so I ran the server without pulling the SSL, but still got this error:

=> Booting Puma
=> Rails 7.0.4.3 application starting in development 
=> Run `bin/rails server --help` for more startup options
Watching: /Users/topher/Library/CloudStorage/Dropbox/TCC-TechDevelopment/Rails/testingNewCreator
  (?-mix:app\/views\/.+\.(erb|haml|slim)$) => on_change
  (?-mix:(app|vendor)\/(assets|javascript)\/\w+\/(.+\.(css|js|html|png|jpg|ts|jsx)).*) => always
#<Thread:0x000000010f3de4a0 /Users/topher/.rvm/gems/ruby-3.2.1/gems/rails_live_reload-0.3.3/lib/rails_live_reload/watcher.rb:59 run> terminated with exception (report_on_exception is true):
/Users/topher/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/socket.rb:1119:in `unix': too long unix socket path (121 bytes given but 104 bytes max) (ArgumentError)

    s = Addrinfo.unix(path).listen
                      ^^^^
        from /Users/topher/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/socket.rb:1119:in `unix_server_socket'
        from /Users/topher/.rvm/gems/ruby-3.2.1/gems/rails_live_reload-0.3.3/lib/rails_live_reload/watcher.rb:60:in `block in start_socket'
Puma starting in single mode...
* Puma version: 5.6.5 (ruby 3.2.1-p31) ("Birdie's Version")
*  Min threads: 5
*  Max threads: 5
*  Environment: development
*          PID: 22519
* Listening on http://127.0.0.1:3000
* Listening on http://[::1]:3000
Use Ctrl-C to stop

Other Issues

I am having another issue that may or may not be related. When I click the browser back button, the bootstrap javascript do not load unless I refresh the page. I am not sure if they don't reload because of a secondary issue, or because I am getting this error with live reload and it is stopping other JS from loading.... though now that I think of it, I still get this error with live_reload when refreshing and the Bootstrap JS loads fine.

Any help you can offer, I would appreciate. Thank you and Happy Coding!

MSchmidt commented 1 year ago

Could you try to move the project closer to your file system root? It has an issue with the socket path and /Users/topher/Library/CloudStorage/Dropbox/TCC-TechDevelopment/Rails/testingNewCreator is quite long.

manastyretskyi commented 1 year ago

Hello👋 For now, @TCCDevelopment you can try to follow @MSchmidt advice and move your project to other folder, since it looks like path is too long. I will try to find some time soon to make a fix for it, or if you want to, you can contribute to the gem and open PR with the fix. I imagine the fix to be some sort of a fallback that will try to open socket in folder like /tmp/sock if current flow fails. Sorry for delay, wasn't able to respond earlier.

TCCDevelopment commented 1 year ago

Could you try to move the project closer to your file system root? It has an issue with the socket path and /Users/topher/Library/CloudStorage/Dropbox/TCC-TechDevelopment/Rails/testingNewCreator is quite long.

Thank you. I will try that solution to see if it works and get back to you.

EDITED:

Tried your solution and when I put it into the `/Users/topher/' folder, it works like a charm. Though this is not where I typically hold my development files to be synced between computers.

TCCDevelopment commented 1 year ago

Hello👋 For now, @TCCDevelopment you can try to follow @MSchmidt advice and move your project to other folder, since it looks like path is too long. I will try to find some time soon to make a fix for it, or if you want to, you can contribute to the gem and open PR with the fix. I imagine the fix to be some sort of a fallback that will try to open socket in folder like /tmp/sock if current flow fails. Sorry for delay, wasn't able to respond earlier.

@manastyretskyi, I am sorry but I won't be able to help with a PR. I am not familiar with sockets in Rails and wouldn't know where to start. I would assume if it is because the path to the repo is so long, that there needs to be an increase on the character count. But, I wouldn't know where to begin with that fix.

TCCDevelopment commented 1 year ago

@MSchmidt and @manastyretskyi, I have tried different folders for cloud accounts that I have (ie OneDrive and iCloud), and both have the same issue. Even when I put the app folder in the root of either cloud drive live_reload errors out. I think this is because I am on an Apple computer and their new requirement for all cloud accounts to be nested inside their /Users/<UserName>/Library/CloudStorage/ folder.

Current Solution For the time being, I am placing my development folders inside a local drive folder, not having it sync between computers as that is not needed currently for me. But, in the future, I would like the auto-backup of cloud storage and so getting this error worked out would be appreciated.

Thank you both for your assistance! Happy Coding!

manastyretskyi commented 1 year ago

@TCCDevelopment please try latest version v0.3.4