Timeouts in Rails/Nginx — Best Practices

2019-07-17 03:23发布

I'm having working on a Rails application that is supposed to run on an Nginx server. Depending on the input, the application may take very long to process the requests (or hang up in case of bugs), so I want to prevent processes from running forever. Apart from the Nginx configuration, which ensures that the client gets a timeout signal, I think I still may have to make sure that my app stops working on those requests. Where should this be handled? Within my Rails app (using Timeout/Thread from std-lib) or externally (killing processes)?

1条回答
太酷不给撩
2楼-- · 2019-07-17 03:48

I usually do this at the Rack layer using Rack::Timeout.

# config/initializers/timeout.rb
Rack::Timeout.timeout = 10  # seconds
查看更多
登录 后发表回答