Skip to content
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

Merged
merged 1 commit into from
Feb 18, 2020

Conversation

patrick-east
Copy link
Contributor

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: #2099
Signed-off-by: Patrick East east.patrick@gmail.com

@patrick-east patrick-east force-pushed the issue/2099 branch 3 times, most recently from 8cba6bd to 89f39ef Compare February 14, 2020 19:14
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>
Copy link
Member

@tsandall tsandall left a 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.

Comment on lines +278 to +281
if !enableRedirect {
client.CheckRedirect = func(*http.Request, []*http.Request) error {
return http.ErrUseLastResponse
}
Copy link
Member

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.

Copy link
Contributor Author

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).

Comment on lines +244 to +246
client := &http.Client{
Timeout: timeout,
}
Copy link
Member

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!

@patrick-east patrick-east merged commit 7e77ac5 into open-policy-agent:master Feb 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add timeout parameter to http.send built-in function
2 participants