ngauthier / tubesock

Websocket interface on Rack Hijack w/ Rails support
MIT License
620 stars 43 forks source link

When Rails reloads in dev environment Tubesock::Hijacked controller crashes rails #17

Open acasajus opened 10 years ago

acasajus commented 10 years ago

The backtrace that pops when rails reloads in dev environment is:

activesupport-4.0.1/lib/active_support/dependencies.rb:446:in `load_missing_constant': A copy of Api::NotificationController has been removed from the module tree but is still active! (ArgumentError)
    from activesupport-4.0.1/lib/active_support/dependencies.rb:184:in `const_missing'
    from app/app/controllers/api/notification_controller.rb:28:in `block (2 levels) in flow'
    from tubesock-0.2.2/lib/tubesock.rb:71:in `call'
    from tubesock-0.2.2/lib/tubesock.rb:71:in `each'
    fromtubesock-0.2.2/lib/tubesock.rb:71:in `close'
    from tubesock-0.2.2/lib/tubesock.rb:66:in `block in listen'

How can I gracefully stop tubesock when rails reloads? Any pointer?

ngauthier commented 10 years ago

hmm, probably just reload your browser (and any tabs open)? I don't think I saw this happen to me when developing.

acasajus commented 10 years ago

I probably didn't explain myself.

ngauthier commented 10 years ago

I'm not really sure. I didn't see this while working on my project.

Does it happen if you run the example project?

https://github.com/ngauthier/sock-chat

Nick

hebnern commented 10 years ago

I believe this is due to running background threads with rails auto-reload enabled. I was getting similar errors, and learned about the problem from this blog post: http://bibwild.wordpress.com/2011/11/14/multi-threading-in-rails-activerecord-3-0-3-1/ (see the config.cache_classes section)

Basically the problem is rails has to unload all classes to support auto-reload, and background threads that are currently executing don't like having their classes pulled out from under them :). Unfortunately the only fix seems to be to disable auto-reload by setting config.cache_classes = true.