Issues with rack-ssl-enforcer after Rails upgrade

rack-ssl-enforcer is great Rack middleware to enforce ssl connections, and to easily specify when to use ssl and when to fall back to http.

I recently upgraded a Rails 3.1.x app to 3.2.6. After deploying with capistrano, the app was breaking on the production vps. What I found was an outdated gem (rack-1.3.6) was being called by rack-ssl-enforcer, even though a newer version (rack-1.4.1) was available.

/home/.../apps/.../releases/.../config/application.rb:9:in `require':
  no such file to load -- rack/ssl-enforcer (LoadError)
  from /home/.../apps/.../releases/.../config/application.rb:9:in `'
  from /home/.../apps/.../releases/.../config/environment.rb:2:in `require'
  from /home/../apps/.../releases/.../config/environment.rb:2:in `'
  from `require'
  from `block in 
' from /home/.../apps/.../shared/bundle/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:51:in `instance_eval'

So the solution to the problem was a simple:

app/current$ bundle clean

which uninstalled the gems not specified in the app’s Gemfile. Note that bundle clean was introduced in version 1.1

Update: Another precaution to take when making changes to the middleware is to stop/start unicorn (or which ever rack server you are using) to ensure the proper gems are being used.

/etc/init.d/unicorn_#{application} stop; /etc/init.d/unicorn_#{application} start;

A simple restart will not reload the stack properly.

blog comments powered by Disqus