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

Set timeout for http.Client #1515

Conversation

chmouel
Copy link
Member

@chmouel chmouel commented Nov 23, 2023

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

  • 📝 A good commit message is important for other reviewers to understand the context of your change. Please refer to How to Write a Git Commit Message for more details how to write beautiful commit messages. We rather have the commit message in the PR body and the commit message instead of an external website.
  • ♽ Run 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 do pre-commit install in the root of this repo).
  • ✨ We heavily rely on linters to get our code clean and consistent, please ensure that you have run make lint before submitting a PR. The markdownlint error can get usually fixed by running make fix-markdownlint (make sure it's installed first)
  • 📖 If you are adding a user facing feature or make a change of the behavior, please verify that you have documented it
  • 🧪 100% coverage is not a target but most of the time we would rather have a unit test if you make a code change.
  • 🎁 If that's something that is possible to do please ensure to check if we can add a e2e test.
  • 🔎 If there is a flakiness in the CI tests then don't necessary ignore it, better get the flakyness fixed before merging or if that's not possible there is a good reason to bypass it. (token rate limitation may be a good reason to skip).

Copy link

codecov bot commented Nov 23, 2023

Codecov Report

Attention: 8 lines in your changes are missing coverage. Please review.

Comparison is base (c0e0e5d) 62.91% compared to head (120fccc) 62.90%.

Files Patch % Lines
pkg/params/clients/clients.go 33.33% 8 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@fabian-heib
Copy link

Why do you not use http.Client Timeout?

Also this case would not be covered by this PR?

@chmouel
Copy link
Member Author

chmouel commented Nov 23, 2023

We used to do this but we have this linter now:
https://github.com/sonatard/noctx

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

@fabian-heib
Copy link

Using both http.Client Timeout and ctx in the request is also good.

https://github.com/openshift-pipelines/pipelines-as-code/blob/0971fd894f3edc1f3658d89e3cd90e6d976caf4f/pkg/matcher/annotation_tasks_install.go#L110C32-L110C32

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]>
@chmouel chmouel force-pushed the issue-1514-http.client-missing-timeout branch from 109ea01 to 120fccc Compare December 4, 2023 08:48
@chmouel
Copy link
Member Author

chmouel commented Dec 4, 2023

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
Copy link
Member Author

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

Copy link

@fabian-heib fabian-heib Dec 4, 2023

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?

@piyush-garg
Copy link
Member

lgtm

@chmouel chmouel merged commit 823ebbb into openshift-pipelines:main Dec 11, 2023
4 checks passed
@chmouel chmouel deleted the issue-1514-http.client-missing-timeout branch December 11, 2023 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

http.Client missing timeout
3 participants