Getting Multi-threaded Thin to Work in Development (Rails 4)

Rails 4

If you’re attempting to run thin to work in threaded mode for the very first time, you might encounter that no matter what you do, your site won’t load.

Running

$ thin start --threaded

Will return the typical startup output

>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3005, CTRL+C to stop

But you’ll never be able to access the site no matter what you do.

This is because in development environment on Rails 4:

[1,2] Rack::Lock wraps the app in mutex so it can only be called by a single thread at a time. Only enabled when config.cache_classes is false.

Not exactly the best solution as you definitely need your cache_classes to be false in development, else you’ll have to keep restarting your server every time you want to make a change.

To fix this, instead, you should just get rid of Rack::Lock.

# config/environments/development.rb
config.middleware.delete Rack::Lock

Restart, and wala!

Reference