-
Notifications
You must be signed in to change notification settings - Fork 93
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
Set timeout for http.Client #1515
Set timeout for http.Client #1515
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1515 +/- ##
==========================================
- Coverage 62.91% 62.90% -0.02%
==========================================
Files 130 130
Lines 10421 10426 +5
==========================================
+ Hits 6556 6558 +2
- Misses 3345 3349 +4
+ Partials 520 519 -1 ☔ View full report in Codecov by Sentry. |
Why do you not use http.Client Timeout? Also this case would not be covered by this PR? |
We used to do this but we have this linter now: they have reasoning why ctx timeout is better... (but i am not a total expert on that so would not be able to argue) the code in there https://github.com/openshift-pipelines/pipelines-as-code/blob)/a43138b10818661de41550fcd71aa24c165cfafd/pkg/matcher/annotation_tasks_install.go#L109-L120 is using the Clients.HTTP as defined with timeout |
Using both http.Client Timeout and ctx in the request is also good. But this does not handle timeout on http request? only on dial defined in the http.Client or does this ctx have a timeout that i'm missing passed to it? |
Used a default of 100 seconds for the timeout. This is the same value as what c# uses by default. I didn't find any other good default. Make annotation_tasks_install.go use the common function instead of defining it's own. Fixes openshift-pipelines#1514 Signed-off-by: Chmouel Boudjnah <[email protected]>
109ea01
to
120fccc
Compare
I think you are right, I cleaned up a bit the code add the timeout directly to the http client and made annotation_matcher using this |
const ( | ||
// most programming languages do not have a timeout, but c# does a default | ||
// of 100 seconds so using that value. | ||
ConnectMaxWaitTime = 100 * time.Second |
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 don't think there is a good value to set, even cloudfare blog don't give much or any
https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/
chatgpt is vague as well, not wanting to give me an average across source code she has seen
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 it depends on the context, if you fetch 10kb of data, then 10s should be fine. If you call an API that create a bunch of resources and update databases and has alot of io in the background, maybe 30s or more is accepted.
Based on what this is used for, 10s is my recommendation, as this is used to fetch files that should not be huge. Maybe add an option as improvement to be able to configure this timeout?
lgtm |
Used a default of 100 seconds for the timeout. This is the same value
as what c# uses by default. I didn't find any other good default.
Make annotation_tasks_install.go use the common function instead of
defining it's own.
Fixes #1514
Changes
Submitter Checklist
make test
before submitting a PR (ie: with pre-commit, no need to waste CPU cycle on CI. (or even better install pre-commit and dopre-commit install
in the root of this repo).make lint
before submitting a PR. The markdownlint error can get usually fixed by runningmake fix-markdownlint
(make sure it's installed first)