-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce :request_timeout option #244
Conversation
The test suite currently fails with this change with the following:
This Lines 285 to 332 in d3c406b
|
0ca2a91
to
a8387f9
Compare
@sneako, I thought of a way to implement this that does work, but it does require spawning another process. I understand if that's an undesirable implementation detail. If you're happy with the changes, I'm happy to squash the commits. |
Thank you @jswanner but yes, spawning a process here is definitely not something we can add to the library, it will severely impact performance. In order to have a very accurate and strict timeout, an additional process is probably necessary, but I was thinking in this case we can have a timeout with much looser guarantees that will still provide some value. Basically this new timeout would be a value which will be decremented by the duration of each individual recv call. This should be "good enough" unless our calls to mint block indefinitely (shouldn't happen unless Does that make sense to you? |
Sorry if this is silly but I always wondered if instead of doing the work in a separate process we could spawn a new process that would sleep for timeout and kill the parent? Something like this: parent = self()
pid =
spawn(fn ->
Process.sleep(1000)
Process.exit(parent, :timeout)
end)
# do work...
Process.exit(pid, :normal) Again this might be a dumb idea and so yeah I believe the best effort approach is warranted here. :) @jswanner btw, I think I briefly saw you on the conference? If so I wish we had a chance to talk more about this! |
@sneako, it does make sense, and that's basically what I tried in the first commit of this PR. Unfortunately some weird stuff was happening in the test that I couldn't explain, it seems an additional request was queued and pipelined then data was received for a different request ref. @wojtekmach that's an interesting idea! I might have to play around with that just for my own curiosity. And yes, we did briefly chat at the very end of the conference. |
a8387f9
to
a8b4b22
Compare
@sneako, I've removed the spawning of a new process, and figured out what was going on. Let me know what you think. |
lib/finch.ex
Outdated
Default value is `15_000`. | ||
|
||
* `:request_timeout` - The maximum time to wait for a complete response before returning an error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should mention how this is a best effort timeout and that the current implementation does not guarantee that the call will return before this amount of time passes. We should also mention that this has only been implemented for HTTP/1.
Thank you so much @jswanner and please accept my apologies for the delays, I've had some major life events happen recently but am finally feeling ready to get back on the horse. I would like to add a bit to the docs for the new option, but otherwise this looks great to me |
Intended to timeout a request with a chunked response after the elapsed time has surpassed the given value. See sneako#243.
a8b4b22
to
f1c0997
Compare
@sneako, hopefully they were happy major life events and not sad ones. Great points on the option's documentation. Let me know what you think of the changes I made. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @jswanner !! ❤️
Intended to timeout a request with a chunked response after the total elapsed time has surpassed the given value. See #243.