When a request takes longer than the timeout limit, the client will receive a 503 response; yet, the server keeps wasting resources (that would be better used on other requests) to create a response that will then be thrown away.
Is there a reasonable way to stop executing a request — in my case, either a Rails controller or a Grape endpoint — after a given timeout, so that as few resources as possible are wasted on a lost battle?
I can think of a hack to do this, and that's why the stress in the previous sentence is on reasonable: it should be safe, reliable and comprehensible, something you wouldn't be too ashamed of committing.
Is anybody already doing it in production?