Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add timeout to requests calls#617

Open
pixeeai wants to merge 4 commits into
Zipstack:mainZipstack/unstract:mainfrom
Pixee-Bot-Python:mainPixee-Bot-Python/Zipstack_unstract:mainCopy head branch name to clipboard
Open

Add timeout to requests calls#617
pixeeai wants to merge 4 commits into
Zipstack:mainZipstack/unstract:mainfrom
Pixee-Bot-Python:mainPixee-Bot-Python/Zipstack_unstract:mainCopy head branch name to clipboard

Conversation

@pixeeai

@pixeeai pixeeai commented Aug 23, 2024

Copy link
Copy Markdown

What, Why & How

Many developers will be surprised to learn that requests library calls do not include timeouts by default. This means that an attempted request could hang indefinitely if no connection is established or if no data is received from the server.

The requests documentation suggests that most calls should explicitly include a timeout parameter. This codemod adds a default timeout value in order to set an upper bound on connection times and ensure that requests connect or fail in a timely manner. This value also ensures the connection will timeout if the server does not respond with data within a reasonable amount of time.

While timeout values will be application dependent, we believe that this codemod adds a reasonable default that serves as an appropriate ceiling for most situations.

Our changes look like the following:

 import requests
 
- requests.get("http://example.com")
+ requests.get("http://example.com", timeout=60)
More reading

Can this PR break any existing features. If yes, please list possible items. If no, please explain why. (PS: Admins do not merge the PR without this section filled)

  • If this logic is not in place, requests could last longer than they should. However, if you do have a request that you know should take more than 60 seconds, then there could be issues but I believe that case to be situational/rare.

Database Migrations

  • N/A

Env Config

  • N/A

Relevant Docs

Related Issues or PRs

  • N/A

Dependencies Versions

  • N/A

Notes on Testing

  • Requests will have a definite time before they are timed out.

Screenshots

Checklist

I have read and understood the Contribution Guidelines.

🧚🤖 Powered by Pixeebot

@CLAassistant

CLAassistant commented Aug 23, 2024

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@sonarqubecloud

Copy link
Copy Markdown

@hari-kuriakose

Copy link
Copy Markdown
Contributor

@johnyrahul @muhammad-ali-e @gaya3-zipstack Looks good overall.
However does the proposed default timeout works out for all our use cases?

url = f"{self.base_url}{endpoint}"
params = {"image_name": image_name, "image_tag": image_tag}
response = requests.get(url, params=params)
response = requests.get(url, params=params, timeout=60)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here It might get issue because, some tools need to be run more than 60 seconds. It's better to do with some env variables,

@chandrasekharan-zipstack

Copy link
Copy Markdown
Contributor

NIT: We also need to ensure we catch and handle Timeout exception. FYI we also have such calls made across other repos as well which might need a review too

Co-authored-by: pixeebot[bot] <104101892+pixeebot[bot]@users.noreply.github.com>
@sonarqubecloud

sonarqubecloud Bot commented Nov 2, 2024

Copy link
Copy Markdown

@pixeeai

pixeeai commented Nov 2, 2024

Copy link
Copy Markdown
Author

NIT: We also need to ensure we catch and handle Timeout exception. FYI we also have such calls made across other repos as well which might need a review too

If there is another repo you have in mind that you'd like for me to scan with pixeebot, feel free to link it here.

Thanks,
Zach

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.

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.