Skip to content

fix(client): add default timeouts to the sdk http session - #271

Merged
rodrigojara-cko merged 2 commits into
mainfrom
fix/INT-1852-default-http-timeouts
Dec 4, 2026
Merged

rodrigojara-cko merged 2 commits into
mainfrom
fix/INT-1852-default-http-timeouts

Conversation

@rodrigojara-cko

@rodrigojara-cko rodrigojara-cko commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The session the SDK creates had no timeout, so a request to an API that accepted the connection and never answered kept the caller waiting with no limit. Requests sent through that session now have a 10 second connect timeout and a 60 second read timeout, and a token request that times out raises an SDK exception.

Changes

  • checkout_sdk/default_http_client.py: DefaultTimeoutSession, a requests.Session that sets timeout=(DEFAULT_CONNECT_TIMEOUT, DEFAULT_READ_TIMEOUT) (10 s, 60 s) on every request that does not pass its own; DefaultHttpClientBuilder creates it.
  • checkout_sdk/oauth_credentials.py: a token request that times out while waiting for the response raises CheckoutAuthorizationException("OAuth token request timed out"), chained to the original error; a connect timeout keeps the existing connection error. get_access_token documents what it raises.
  • README.md: a "Timeouts" section with the defaults, the exceptions, that the connect bound does not include the DNS lookup, and an example of a session with other bounds (an HTTPAdapter mounted on a plain Session that sets (5, 30) on every request that passes no timeout, by name or by position); the custom HttpClientBuilderInterface example keeps the defaults with DefaultTimeoutSession.
  • Tests: tests/default_http_client_test.py (new), tests/api_client_timeout_test.py (new), tests/oauth_credentials_test.py, tests/checkout_test_utils.py (local server that accepts the connection and never answers).

Design notes: requests has no session-wide timeout, so the SDK session sets it per request with setdefault, which keeps a timeout passed by the call. A session from http_client_builder is used as given: the SDK does not change a client the application configured. Unlike the Java SDK, the token request of a custom session gets no deadline from the SDK: Python token requests are not serialized (there is no lock in oauth_credentials.py), so a hung one blocks only its caller, and the merchant's session is used as is. A timeout passed by position is kept too: DefaultTimeoutSession is public so an application can reuse it, and adding the default next to a positional timeout would raise a TypeError. A token read timeout is mapped to CheckoutAuthorizationException with a fixed message, as the Java SDK does for its token request, so callers handle every token failure with one exception type. A token response body that stops arriving is raised by requests as a ConnectionError (requests/models.py, iter_content), so it keeps the existing "Unable to establish connection" message even though the connection was made; the comment and the docstring say so. DefaultTimeoutSession is public so a custom session can reuse it, as the README shows; DEFAULT_CONNECT_TIMEOUT and DEFAULT_READ_TIMEOUT document the values.

API Reference

None. No request or response changes.

Breaking changes

None in the public signatures. Behaviour changes, released as a minor version (a correction of requests that could wait with no limit):

  • A request through the session the SDK creates that gets no answer now fails after the bound (10 s to connect and send the request, 60 s between bytes of the response) instead of waiting with no limit. This cannot be kept compatible: the bound is the fix. Migration: to use other bounds, provide a session through http_client_builder.
  • A token request that times out while waiting for the response, also with a session from http_client_builder that sets its own timeout, raises CheckoutAuthorizationException instead of the requests ReadTimeout. Needed so a token failure is an SDK exception: the HTTP error and connection failures of the token request already are, and an API request that times out with such a session is already raised as CheckoutException (api_client.py, the except OSError branch); the token read timeout was the only requests exception that reached the caller. Migration: code that catches requests.exceptions.Timeout or RequestException around the SDK catches CheckoutAuthorizationException instead (it is not an OSError).

Tests

  • Existing tests pass
  • Serialization tests cover every new or changed property: not applicable, no request or response type changed
  • README updated if documented usage changed

The new tests check the default on every request of the SDK session, a timeout passed by the call by name or by position, a custom session left untouched, an API request and a token request against a local server that never answers (each fails within the bound with the SDK exception), and the connection message kept for a token connect timeout.

Related

None.

@rodrigojara-cko
rodrigojara-cko requested a review from a team December 1, 2026 11:32
@agent-wall-e

agent-wall-e Bot commented Dec 1, 2026

Copy link
Copy Markdown

🔴 Risk Classification: MAJOR

Approval route: AI Review + Human Approval Required
Rollback controls: Change-freeze window + documented rollback plan

Classification reasons

  • security_sensitive_path:checkout_sdk/oauth_credentials.py
  • security_sensitive_path:tests/oauth_credentials_test.py

Operational gates

  • ✅ jira_ticket (INT-1852)
  • ✅ independent_review

Files analysed: 7


wall-e 2026.06.19-02 · policy 6b4ce2b3b45a…

@agent-wall-e

agent-wall-e Bot commented Dec 1, 2026

Copy link
Copy Markdown
🔬 Debug — why this classification?

Each reason code emitted by the classifier, its source clause in the AI in SDLC Control Framework, and what it means.

Reason code Kind Clause Meaning
security_sensitive_path — checkout_sdk/oauth_credentials.py classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).
security_sensitive_path — tests/oauth_credentials_test.py classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).

Kinds:

  • classifying — this rule contributed to the chosen tier.
  • informational — context only; did not by itself decide the tier.

See issue #3 for the proposal to formalise this map as Appendix A of the standards doc.

wall-e 2026.06.19-02 · debug

@agent-wall-e

agent-wall-e Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

🟠 Advisory review: Concerns worth a look

This PR needs a human approval. Before you give it, these are the things I'd want resolved.

Adds default 10s connect / 60s read timeouts to the SDK session and maps token timeout to CheckoutAuthorizationException; the implementation is largely correct but the positional-argument guard in DefaultTimeoutSession has an off-by-one that could silently drop the default timeout.

Concerns

  • In default_http_client.py, _TIMEOUT_POSITION = 6 and the guard is if len(args) <= self._TIMEOUT_POSITION, but args starts after method and url, so timeout is the 7th parameter of Session.request overall but the 5th element of *args (index 4: params, data, headers, cookies, files, auth, timeout → index 6 in full signature but index 4 in *args after method/url are stripped). The comment says 'params, data, headers, cookies, files, auth, timeout' which is 7 items after method/url, making the correct index 6 in *args — but that needs verification against the actual requests.Session.request signature to be sure the count is right. If the index is wrong, a positional timeout could be silently ignored and the default applied on top, or the default could be skipped when no positional timeout was passed.
  • The Timeout except branch in oauth_credentials.py is placed after the ConnectionError branch, but requests.exceptions.ConnectTimeout is a subclass of both ConnectionError and Timeout — the existing ConnectionError handler catches it first, which is the documented intent. However ReadTimeout is only a Timeout, so it correctly falls through to the new branch. This ordering is correct but subtle and worth a comment confirming the precedence is intentional (the existing comment partially does this but could be clearer).
  • The unresponsive_server context manager appends connections to a plain list from the acceptor thread while the main thread iterates it in finally — this is a benign race in tests but technically unsynchronised shared state.
  • The timeout integration tests use monkeypatch.setattr(default_http_client, 'DEFAULT_READ_TIMEOUT', 0.5) but DefaultHttpClientBuilder().get_client() is called after the patch — this works because DefaultTimeoutSession.request reads the module-level name at call time, not at construction time. This is correct but fragile: if the implementation were ever changed to capture the value at construction, the tests would silently stop testing the short timeout.
  • The test_should_keep_a_timeout_passed_by_position_to_the_request_of_the_default_session test passes 9 positional arguments ('GET', 'https://example.com/', None, None, None, None, None, None, 7) — after method and url are consumed, args has 7 elements (indices 0–6), and timeout is at index 6 (_TIMEOUT_POSITION). The guard len(args) <= 6 evaluates to 7 <= 6 which is False, so the default is correctly skipped. This confirms the index arithmetic is internally consistent, but reviewers should independently verify it matches the actual requests.Session.request parameter order.

This is not an approval. wall-e cannot auto-approve this PR — it is an opinion to help whoever does. Advisory review · us.anthropic.claude-sonnet-4-6 · wall-e 2026.06.19-02

@rodrigojara-cko
rodrigojara-cko force-pushed the fix/INT-1852-default-http-timeouts branch from a21e5a3 to e6ecfee Compare December 1, 2026 15:29
@agent-wall-e

agent-wall-e Bot commented Dec 1, 2026

Copy link
Copy Markdown

🔴 Risk Classification: MAJOR

Approval route: AI Review + Human Approval Required
Rollback controls: Change-freeze window + documented rollback plan

Classification reasons

  • security_sensitive_path:checkout_sdk/oauth_credentials.py
  • security_sensitive_path:tests/oauth_credentials_test.py

Operational gates

  • ✅ jira_ticket (INT-1852)
  • ✅ independent_review

Files analysed: 7


wall-e 2026.06.19-02 · policy 6b4ce2b3b45a…

@agent-wall-e

agent-wall-e Bot commented Dec 1, 2026

Copy link
Copy Markdown
🔬 Debug — why this classification?

Each reason code emitted by the classifier, its source clause in the AI in SDLC Control Framework, and what it means.

Reason code Kind Clause Meaning
security_sensitive_path — checkout_sdk/oauth_credentials.py classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).
security_sensitive_path — tests/oauth_credentials_test.py classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).

Kinds:

  • classifying — this rule contributed to the chosen tier.
  • informational — context only; did not by itself decide the tier.

See issue #3 for the proposal to formalise this map as Appendix A of the standards doc.

wall-e 2026.06.19-02 · debug

@rodrigojara-cko
rodrigojara-cko force-pushed the fix/INT-1852-default-http-timeouts branch from e6ecfee to dbf75a7 Compare December 1, 2026 16:51
@agent-wall-e

agent-wall-e Bot commented Dec 1, 2026

Copy link
Copy Markdown

🔴 Risk Classification: MAJOR

Approval route: AI Review + Human Approval Required
Rollback controls: Change-freeze window + documented rollback plan

Classification reasons

  • security_sensitive_path:checkout_sdk/oauth_credentials.py
  • security_sensitive_path:tests/oauth_credentials_test.py

Operational gates

  • ✅ jira_ticket (INT-1852)
  • ✅ independent_review

Files analysed: 7


wall-e 2026.06.19-02 · policy 6b4ce2b3b45a…

@agent-wall-e

agent-wall-e Bot commented Dec 1, 2026

Copy link
Copy Markdown
🔬 Debug — why this classification?

Each reason code emitted by the classifier, its source clause in the AI in SDLC Control Framework, and what it means.

Reason code Kind Clause Meaning
security_sensitive_path — checkout_sdk/oauth_credentials.py classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).
security_sensitive_path — tests/oauth_credentials_test.py classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).

Kinds:

  • classifying — this rule contributed to the chosen tier.
  • informational — context only; did not by itself decide the tier.

See issue #3 for the proposal to formalise this map as Appendix A of the standards doc.

wall-e 2026.06.19-02 · debug

@rodrigojara-cko
rodrigojara-cko force-pushed the fix/INT-1852-default-http-timeouts branch from dbf75a7 to 1f11bf8 Compare December 3, 2026 16:04
@agent-wall-e

agent-wall-e Bot commented Dec 3, 2026

Copy link
Copy Markdown

🔴 Risk Classification: MAJOR

Approval route: AI Review + Human Approval Required
Rollback controls: Change-freeze window + documented rollback plan

Classification reasons

  • security_sensitive_path:checkout_sdk/oauth_credentials.py
  • security_sensitive_path:tests/oauth_credentials_test.py

Operational gates

  • ✅ jira_ticket (INT-1852)
  • ✅ independent_review

Files analysed: 7


wall-e 2026.06.19-02 · policy 6b4ce2b3b45a…

@agent-wall-e

agent-wall-e Bot commented Dec 3, 2026

Copy link
Copy Markdown
🔬 Debug — why this classification?

Each reason code emitted by the classifier, its source clause in the AI in SDLC Control Framework, and what it means.

Reason code Kind Clause Meaning
security_sensitive_path — checkout_sdk/oauth_credentials.py classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).
security_sensitive_path — tests/oauth_credentials_test.py classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).

Kinds:

  • classifying — this rule contributed to the chosen tier.
  • informational — context only; did not by itself decide the tier.

See issue #3 for the proposal to formalise this map as Appendix A of the standards doc.

wall-e 2026.06.19-02 · debug

The session the SDK creates when no http_client_builder is set had no
timeout, and requests waits forever by default, so a stalled connection
blocked the caller indefinitely.

Behaviour change: requests made through the SDK-created session now use a
10 second connect timeout and a 60 second read timeout, unless a timeout is
passed for the call. A session returned by a custom http_client_builder is
used as is; the README shows how to set bounds on it.
With the default timeouts a stalled token request now ends in a read
timeout. That error is not a ConnectionError, so the raw requests exception
reached the caller instead of an SDK exception.

The token request now raises CheckoutAuthorizationException("OAuth token
request timed out") for a read timeout, chained to the original error, with
a fixed message like the other token errors. A connect timeout is a
ConnectionError and keeps its message. API requests that time out keep
raising CheckoutException, now covered by a test against a server that
never answers.

Behaviour change, also with a session from http_client_builder that sets
its own timeout: a token request read timeout used to reach the caller as
requests ReadTimeout and is now CheckoutAuthorizationException.
@rodrigojara-cko
rodrigojara-cko force-pushed the fix/INT-1852-default-http-timeouts branch from 1f11bf8 to b280753 Compare December 4, 2026 12:49
@agent-wall-e

agent-wall-e Bot commented Dec 4, 2026

Copy link
Copy Markdown

🔴 Risk Classification: MAJOR

Approval route: AI Review + Human Approval Required
Rollback controls: Change-freeze window + documented rollback plan

Classification reasons

  • security_sensitive_path:checkout_sdk/oauth_credentials.py
  • security_sensitive_path:tests/oauth_credentials_test.py

Operational gates

  • ✅ jira_ticket (INT-1852)
  • ✅ independent_review

Files analysed: 7


wall-e 2026.06.19-02 · policy 6b4ce2b3b45a…

@agent-wall-e

agent-wall-e Bot commented Dec 4, 2026

Copy link
Copy Markdown
🔬 Debug — why this classification?

Each reason code emitted by the classifier, its source clause in the AI in SDLC Control Framework, and what it means.

Reason code Kind Clause Meaning
security_sensitive_path — checkout_sdk/oauth_credentials.py classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).
security_sensitive_path — tests/oauth_credentials_test.py classifying §2.1 M4/M5 Path matched a sensitive pattern (auth, secrets, crypto, PCI, migrations, network IaC).

Kinds:

  • classifying — this rule contributed to the chosen tier.
  • informational — context only; did not by itself decide the tier.

See issue #3 for the proposal to formalise this map as Appendix A of the standards doc.

wall-e 2026.06.19-02 · debug

@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

@rodrigojara-cko
rodrigojara-cko merged commit bfe623b into main Dec 4, 2026
4 checks passed
@rodrigojara-cko
rodrigojara-cko deleted the fix/INT-1852-default-http-timeouts branch December 4, 2026 16:18
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.

2 participants