Wednesday, July 22, 2009

Sporadic IOError and Undefined Method Errors that Happen Under Load in JRuby-rack 0.9.4

If you are getting errors like these in your JRuby 1.3.1/Sinatra 0.9.2/JRuby-rack 0.9.4 app under load, upgrade to JRuby-rack 0.9.5 or later (the following was tested with jruby-rack-0.9.5-20090625.190033-5.jar). Then follow the instructions in "How to Get Warbler to Include a Custom Version of JRuby and JRuby-rack" to use it with warbler. Thanks so much to Nick Sieger for pointing me to the newer snapshot to help with these issues!

Without that latest jruby-rack (0.9.5 snapshot), we were getting all kinds of sporatic errors like:

ERROR [TP-Processor25] Jul/17 16:47:11,379 [localhost].[/myapp].[] -
 Exception caught
 /path/to/tomcat5.5/path/to/app/WEB-INF/gems/gems/rack-1.0.0/lib/rack/request.rb:142:in
 `POST': IO Error (IOError)
ERROR [TP-Processor10] Jul/17 16:44:48,516 [localhost].[/myapp].[] -
 Exception caught
 /path/to/tomcat5.5/path/to/app/WEB-INF/gems/gems/rack-1.0.0/lib/rack/request.rb:142:in
 `POST': Broken pipe - Broken pipe (Errno::EPIPE)
NoMethodError at /path/handled/by/sinatra/controller
 undefined method `name_of_my_method' for
 #
   * file:  base.rb
   * location: route
   * line: 779
Charlie Nutter mentioned the following for those encountering wierd undefined method errors:
I wonder if it's doing some autoloading somewhere? Or if there's some other kind of lazy loading of code? Generally when you see this sort of thing under load it means that one thread has initiated some code to load or some class to be modified, and another thread is seeing a partial result of that change. Autoloads are a classic culprit, since they're not thread-safe, but code that conditionally or lazily includes modules or modifies classes can be a culprit too. - Charlie

No comments: