Skip to content

Conversation

@ofipify
Copy link
Contributor

@ofipify ofipify commented Aug 11, 2025

Over the last few days we've noticed that the default timeout of 10 seconds was a bit too low. This PR makes this value configurable. and increases it to 30 seconds. Originally I did not want to increase the default value, but then ran into timeouts when running the tests locally so decided to bump it to 30 seconds. Default timeout of 10 seconds was kept.

Fixes #140

@coderabbitai
Copy link

coderabbitai bot commented Aug 11, 2025

Summary by CodeRabbit

  • New Features

    • Per-instance network timeout configuration for clients.
    • Default timeout set to 10 seconds.
    • Token acquisition and requests now consistently honor the configured timeout.
  • Refactor

    • Streamlined request handling to improve consistency; no user-facing behavior changes beyond timeout configuration.

Walkthrough

Moves network timeout configuration to the Client instance: adds DEFAULT_NETWORK_TIMEOUT = 10.0, extends Client.init with timeout, passes timeout into Request, and refactors Request to store and use an instance timeout and instance-bound get/post callbacks (removes module-level NETWORK_TIMEOUT).

Changes

Cohort / File(s) Summary
Client timeout configurability
epo_ops/api.py
Added DEFAULT_NETWORK_TIMEOUT = 10.0. Extended Client.__init__(..., timeout=DEFAULT_NETWORK_TIMEOUT), stored self.timeout, passed timeout into Request(...), and used self.timeout when acquiring tokens.
Request refactor for per-instance timeout
epo_ops/models.py
Removed module-level NETWORK_TIMEOUT and module-level _post/_get callbacks. Updated Request.__init__(..., timeout=None) to store self.timeout. Converted _post_callback and _get_callback to instance methods and have post/get dispatch to these instance-bound callbacks using self.timeout. Middleware flow preserved.

Sequence Diagram(s)

sequenceDiagram
  actor User
  participant Client
  participant Request
  participant HTTP

  User->>Client: Client(key, secret, timeout=...)
  Client->>Request: Request(middlewares, timeout)
  Client->>HTTP: Acquire token (timeout=Client.timeout)

  User->>Client: client.get/post(...)
  Client->>Request: _request(method, url, data)
  Request->>Request: apply pre-middlewares
  Request->>HTTP: _get/_post (timeout=Request.timeout)
  HTTP-->>Request: response
  Request->>Request: apply post-middlewares
  Request-->>Client: response
  Client-->>User: response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Assessment against linked issues

Objective Addressed Explanation
Make network timeout configurable at client instantiation (#140)
Keep default timeout at 10 seconds as before (#140)

Poem

I twitched my whiskers, set the pace,
Ten seconds steady for each race.
Each client now may choose its nap,
A punctual hop, a courteous tap.
I nibble code and stamp my paw—timeout, hooray! 🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bd2ed6b and cdb147a.

📒 Files selected for processing (2)
  • epo_ops/api.py (3 hunks)
  • epo_ops/models.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • epo_ops/api.py
  • epo_ops/models.py
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🔭 Outside diff range comments (1)
epo_ops/models.py (1)

111-116: Fix syntax error and avoid duplicate 'timeout' kwarg in requests calls

Current calls use **kwargs, timeout=self.timeout, which is invalid syntax and can also conflict if timeout is present in kwargs. Set it on kwargs first, then unpack.

-    def _post_callback(self, url, data, **kwargs):
-        return requests.post(url, data, **kwargs, timeout=self.timeout)
+    def _post_callback(self, url, data, **kwargs):
+        if self.timeout is not None:
+            kwargs.setdefault("timeout", self.timeout)
+        return requests.post(url, data=data, **kwargs)
 
-    def _get_callback(self, url, data, **kwargs):
-        return requests.get(url, **kwargs, timeout=self.timeout)
+    def _get_callback(self, url, data, **kwargs):
+        if self.timeout is not None:
+            kwargs.setdefault("timeout", self.timeout)
+        return requests.get(url, **kwargs)
🧹 Nitpick comments (3)
epo_ops/api.py (3)

38-38: Consider typing the timeout to match requests’ accepted types

Requests accepts float or (connect, read) tuple. Typing this improves clarity.

-from typing import List, Optional, Union
+from typing import List, Optional, Union, Tuple
@@
-    def __init__(self, key, secret, accept_type="xml", middlewares=None, timeout=DEFAULT_NETWORK_TIMEOUT):
+    def __init__(self, key, secret, accept_type="xml", middlewares=None, timeout: Union[float, Tuple[float, float]] = DEFAULT_NETWORK_TIMEOUT):

43-43: Name the timeout argument when constructing Request

Minor readability and future-proofing against positional changes.

-        self.request = Request(self.middlewares, timeout)
+        self.request = Request(self.middlewares, timeout=timeout)

46-46: Optionally assign self.timeout before creating Request

Purely for readability so the instance state is set before dependent components are built.

-        self.request = Request(self.middlewares, timeout)
-        self.key = key
-        self.secret = secret
-        self.timeout = timeout
+        self.key = key
+        self.secret = secret
+        self.timeout = timeout
+        self.request = Request(self.middlewares, timeout=timeout)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 54a7661 and bd2ed6b.

📒 Files selected for processing (2)
  • epo_ops/api.py (3 hunks)
  • epo_ops/models.py (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
epo_ops/api.py (3)
epo_ops/middlewares/throttle/throttler.py (1)
  • Throttler (13-26)
epo_ops/models.py (1)
  • Request (66-115)
tests/conftest.py (2)
  • default_client (35-40)
  • reset_cached_client (13-21)
🔇 Additional comments (2)
epo_ops/models.py (1)

86-90: Good refactor to instance-bound callbacks

Dispatching via self._post_callback/self._get_callback enables per-instance timeouts cleanly.

epo_ops/api.py (1)

355-356: Token acquisition now honors per-instance timeout — good

Using self.timeout here aligns token requests with the client’s configured timeout.

This also increases the default to 30 seconds
@codecov
Copy link

codecov bot commented Sep 9, 2025

Codecov Report

❌ Patch coverage is 66.66667% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.72%. Comparing base (54a7661) to head (cdb147a).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
epo_ops/models.py 50.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #141       +/-   ##
===========================================
- Coverage   99.31%   77.72%   -21.59%     
===========================================
  Files          18       18               
  Lines         438      440        +2     
===========================================
- Hits          435      342       -93     
- Misses          3       98       +95     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@amotl amotl left a comment

Choose a reason for hiding this comment

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

Thank you very much.

@amotl amotl merged commit eaffa57 into ip-tools:main Sep 9, 2025
6 checks passed
@ofipify
Copy link
Contributor Author

ofipify commented Sep 10, 2025

@amotl thanks for merging this. Much appreciated.

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.

Default NETWORK_TIMEOUT might be too low and should be configurable

2 participants