-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add timeout for http.send
builtin
#2105
Add timeout for http.send
builtin
#2105
Conversation
8cba6bd
to
89f39ef
Compare
There is a new optional `timeout` option to specify with `http.send` which will set a client timeout on the request. This will override the default 5 second timeout. This change also corrects the request to use the builtin context. This means that if the evaluation is canceled the request will also now be canceled. There is an environment variable for adjusting the default timeout which we should aim to remove in future OPA versions (when appropriate). For now though it is still supported, and will panic if supplied with an invalid value rather than previously ignoring it and effectively disable the timeout (0 == unlimited). Fixes: open-policy-agent#2099 Signed-off-by: Patrick East <east.patrick@gmail.com>
89f39ef
to
7b19c10
Compare
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.
LGTM. Feel free to merge whenever.
if !enableRedirect { | ||
client.CheckRedirect = func(*http.Request, []*http.Request) error { | ||
return http.ErrUseLastResponse | ||
} |
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.
Is this an important fix? What was happening before? Maybe a comment would be useful for our future selves.
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.
Nothing changed with the behavior, its just a refactor with how the client is being created. It used to set this explicitly on the client creation and then nil
it out if redirects are enabled. Now we don't set it when creating the client and just update it as needed (when redirects are disabled).
client := &http.Client{ | ||
Timeout: timeout, | ||
} |
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.
👌 this should cover the end to end timeout from dial to response body received. nice!
There is a new optional
timeout
option to specify withhttp.send
which will set a client timeout on the request. This will override the
default 5 second timeout.
This change also corrects the request to use the builtin context. This
means that if the evaluation is canceled the request will also now be
canceled.
There is an environment variable for adjusting the default timeout
which we should aim to remove in future OPA versions (when
appropriate). For now though it is still supported, and will panic if
supplied with an invalid value rather than previously ignoring it and
effectively disable the timeout (0 == unlimited).
Fixes: #2099
Signed-off-by: Patrick East east.patrick@gmail.com