rmosolgo / react-rails-hot-loader

Live-reload React.js components with Ruby on Rails & react-rails
MIT License
88 stars 26 forks source link

Rails Server crashes on page reload #14

Open djkz opened 7 years ago

djkz commented 7 years ago

Happens sometimes when hard reloading jasmine-rails specs page, haven't been able to figure out what causes it exactly:

/usr/local/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/eventmachine-1.0.8/lib/eventmachine.rb:534:in `start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError)
        from /usr/local/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/eventmachine-1.0.8/lib/eventmachine.rb:534:in `start_server'
        from /usr/local/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/em-websocket-0.5.1/lib/em-websocket/websocket.rb:46:in `run'
        from /usr/local/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/react-rails-hot-loader-0.7.0/lib/hot_loader/server.rb:70:in `run_websocket_server'
        from /usr/local/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/react-rails-hot-loader-0.7.0/lib/hot_loader/server.rb:33:in `block in start'
rmosolgo commented 7 years ago

Interesting, my Rails server doesn't crash on that error, so I didn't bother handling it.

You can see here where we try to start a Websocket server:

https://github.com/rmosolgo/react-rails-hot-loader/blob/master/lib/hot_loader/server.rb#L70

If the server is already running, :boom:! I guess we should either check for the server ahead of time or handle that error more gracefully.

djkz commented 7 years ago

I added another rescue around that block, but I'm not sure a good way to write a test for it, so I'm not creating a pull request.

We can close this issue and add the fix for it if anyone else has that problem.

rmosolgo commented 7 years ago

Yeah, it's so hard to test that part of this thing!! Did you push the change to GitHub? If you're able to link to it from here, it might help someone else, or I might PR it anyways :)

djkz commented 7 years ago

My changes are in here: https://github.com/djkz/react-rails-hot-loader/blob/master/lib/hot_loader/server.rb

Fercell commented 7 years ago

I am experiencing the same issue as well. The server just crashes with the same error message.

fernandobrito commented 7 years ago

I also had this problem and @djkz solution seems to have fixed it. Should we submit a PR?

leonbsilva commented 6 years ago

the @djkz solution fixed bug in ruby 2.5.1 (There wasn't the error in using version 0.7.0 and ruby 2.4.4)