Pausing timeout while generating response

I’m using the warp package for a web server implementation. I have a handler that can take a very long time to generate a response. I have tried using pauseTimeout, however it does not appear to work. My response handler is killed after 60s (I am running the server with the default timeout, which is 30s, and I believe it’s expected that it can take exactly twice the timeout before it will act, so this is fine).

pauseTimeout may only be intended for pausing timeouts on reading the request body, and not in generating a response. In the issue linked to from pauseTimeout doc (and the reason for its existence), spl lists several possible workarounds: Timeout left running after use of sourceRequestBody · Issue #351 · yesodweb/wai · GitHub.

Of these, #2 I think does not apply (I do not want to avoid logging a timeout, I want to completely ignore). #3 is not possible anymore (The Timeout module appears to have been removed, I don’t think it’s possible to access the timeout manager through Warp anymore. If this is incorrect, it would be a great approach). This leaves #1. Edit: TimeoutThread does not appear to be exposed, so #1 might not be an option either.

If I went the route of #1 above, how would I go about ignoring an exception? By ignoring here I mean not handling it, and allowing code to continue executing when exceptions of certain types are thrown against its thread. I don’t want to mask all exceptions, and I can’t catch TimeoutThread the usual way, as that will abort the IO action generating the response and I can’t resume it where it was at.

I am aware of the XY problem, and have provided quite a bit of X above, so if I’m using the entirely wrong approach here or have missed something please let me know a better way to go about doing this.

2 Likes

Generally HTTP connections should be short. Most HTTP clients also have a timeout that will have to be disabled.

Other options:

  • kick off an async process and have another endpoint for fetching the response
  • web sockets

I’ve ported this application from Go, so it’s frustrating to see the support for simple things not available in Haskell.

1 Like