views:

288

answers:

0

I am getting a really strange error from ActiveResource. I have a method that calls another system to get a list of products. The list is quite large and takes about 3 minutes to generate and transfer. Since this is really only a once a day kinda thing I built a rake task to run it. In production whenever I run the rake task it fails with a 500 error. Here is some sample output

$ time RAILS_ENV=production rake api:sync
rake aborted!
Failed with 500 Internal Server Error

(See full trace by running task with --trace)

real    2m1.753s
user    0m1.188s
sys 0m0.188s

Then I tried to use script runner:

$ RAILS_ENV=production script/runner 'Product.synchronize!(ProductManager::Product.find_valid_products)'
/var/www/apps/api/releases/20091202203413/vendor/rails/railties/lib/commands/runner.rb:48: Failed with 500 Internal Server Error (ActiveResource::ServerError)
    from /usr/local/lib/ruby/1.8/net/protocol.rb:133:in `rbuf_fill'
    from /usr/local/lib/ruby/1.8/timeout.rb:62:in `timeout'
    from /usr/local/lib/ruby/1.8/timeout.rb:93:in `timeout'
    from /usr/local/lib/ruby/1.8/net/protocol.rb:132:in `rbuf_fill'
    from /usr/local/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
    from /usr/local/lib/ruby/1.8/net/protocol.rb:126:in `readline'
    from /usr/local/lib/ruby/1.8/net/http.rb:2020:in `read_status_line'
    from /usr/local/lib/ruby/1.8/net/http.rb:2009:in `read_new'
     ... 17 levels...
    from /var/www/apps/api/releases/20091202203413/vendor/rails/railties/lib/commands/runner.rb:48
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from script/runner:3

However if I jump into the console to run it, everything is fine:

$ script/console production
Loading production environment (Rails 2.3.5)
>> Product.synchronize!(ProductManager::Product.find_valid_products); nil # prevent dump to console
=> nil
>>

I suspected it was a timeout, so I set the timeout value to 5 minutes on the ProductManager::Product class, but that had no effect. The interesting thing is that when I run via rake or script/runner the error happens occurs at 2 minutes and 1 second without fail. In development and staging there is no issue. Does production of ActiveResource have some kind of hidden 2 minute override I can't find?

In case you didn't get it from the traces, we are using Rails 2.3.5 frozen into the application. Thanks for you help

Peer