Atomic Object’s blog on everything we find fascinating.

JRuby, Rails, and Jetty – Where Are my Assets?

Recently, I was spinning up an extremely simple Rails 4 project, which was to serve as a portal to several other applications deployed on the same Jetty instance. This was not my first JRuby on Rails rodeo, so I was expecting a smooth deployment.

When I deployed the WAR into a Jetty instance on my local machine, neither the CSS nor images were being served correctly. The application server was giving me a 200 return code with the correct content length header, and then giving me a zero-byte response. Having never encountered this issue before, I talked to my pair on the project, who was standing up a separate Rails 4 app for the same application server. He was seeing it too. We compared notes. Heads were scratched.

As a sanity check, I spun up an Apache Tomcat server and deployed the same WAR file there. Everything was fine! My compiled CSS and locally hosted placekittens were being served without issue.

With the application working in Tomcat, I assumed that the basic configuration of the application was probably okay, and hit Google searching for potential answers. I twiddled some of the settings dealing with serving of static assets in config/production.rb to no success. I modified the asset compilation settings as suggested in severalpromising StackOverflow questions, with no luck.

Wondering if this could possibly be an issue with either the version of JRuby or Jetty being run on my machine, I compared versions with my coworker who was also experiencing issues. Different versions of both JRuby and Jetty were involved. I assumed that an issue this easily reproduced would not have survived more than a point release of either project, and moved on.

At this point, I moved on to the github issuetrackers of the various projects that support the JRuby on Rails stack which touch static assets. I found, tested, and discarded some relevant-looking bugs, which turned out to not be the cause of my issue. Eventually, I found the one. I downgraded jruby-rack to 1.1.13, and my placekittens appeared! This appears to be some strange interaction between Jetty and the way jruby-rack was capturing responses from the hosted applet.

In short, if you’re working with Rails 4 on Jetty and your static assets (css, html, images) aren’t showing up, try a different version of jruby-rack. If you don’t need the new features introduced by 1.1.14, you can downgrade. If you do, you should have better luck pointing bundler at the 1.1 stable branch. Have you encountered any frustratingly simple bugs recently? Give me a shout in the comments.