Skip to content

Allow configurable timeouts for PycurlClient - #1975

Merged
mark-kogan-stripe merged 4 commits into
stripe:masterfrom
itsrayeedscodespace:fix/1962-pycurl-configurable-timeouts
Nov 13, 2026
Merged

mark-kogan-stripe merged 4 commits into
stripe:masterfrom
itsrayeedscodespace:fix/1962-pycurl-configurable-timeouts

Conversation

@itsrayeedscodespace

@itsrayeedscodespace itsrayeedscodespace commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1962

PycurlClient hardcodes its connection and total request timeouts, so callers currently have to override a private method to configure them.

This adds keyword-only timeout: int = 80 and connect_timeout: int = 30 constructor arguments and applies them on every request after the curl handle is reset. Existing positional arguments, including the internal _lib hook, retain their positions. Defaults remain 80 seconds for the whole transfer and 30 seconds for connection establishment. The same request path handles buffered and streamed responses and proxy configuration.

Regression tests cover defaults, either timeout overridden independently, both overridden together, streaming, reapplying options on a reused curl handle, positional compatibility, and keyword-only enforcement. Tests run for the direct client and both existing proxy variants. Running these tests against upstream's pre-fix client produced 18 failures and 3 passing default cases. Keeping the new constructor but restoring hardcoded curl options produced 15 failures and 3 passing default cases, confirming that the tests also detect incorrect request execution.

Changelog: .hark/changes/2026-11-06_itsrayeedscodespace_pycurl-configurable-timeouts.change.md (minor feature, links #1962).

Validated on macOS arm64 with fresh environments, repository-pinned tooling, and stripe-mock 0.206.0 serving the repository's pinned OpenAPI v2596 spec and fixtures:

Command Result
/tmp/stripe-1962-validation/bin/pytest tests/test_http_client.py -n 0 Python 3.13.18: 151 passed
/tmp/stripe-1962-validation/bin/pytest -n 4 Python 3.13.18: 4,405 passed, 7 skipped
/tmp/stripe-1962-python39/bin/pytest tests/test_http_client.py -n 0 Python 3.9.6: 151 passed
/tmp/stripe-1962-python39-openssl/bin/pytest -n 4 Python 3.9.25: 4,405 passed, 7 skipped
/tmp/stripe-1962-validation/bin/python -m flake8 --show-source stripe tests Passed
/tmp/stripe-1962-validation/bin/ruff format . --check Passed; 1,738 files already formatted
PYRIGHT_PYTHON_IGNORE_WARNINGS=1 /tmp/stripe-1962-validation/bin/pyright --pythonpath /tmp/stripe-1962-validation/bin/python 0 errors, 0 warnings
/tmp/stripe-1962-validation/bin/mypy Passed; 2 source files
/tmp/stripe-1962-validation/bin/python -m build --outdir /tmp/stripe-1962-tools/dist Built sdist and wheel
/tmp/stripe-1962-validation/bin/python -m twine check /tmp/stripe-1962-tools/dist/* Both artifacts passed
/tmp/stripe-1962-tools/hark validate Validated 629 changefiles
git diff --check upstream/master...HEAD Passed

An additional local HTTP-server smoke check with real PycURL 7.49.0 passed for defaults, individual/combined overrides, buffered/streamed/reused requests, and positional _lib calls. It also confirmed that the curl options reject floats and None. PycURL was then removed from the static-check environment to match the declared test/dev dependencies; its installed wheel otherwise makes two existing import-ignore comments unnecessary.

The initial full run on Apple's Python 3.9.6 had four export-test failures because its LibreSSL/urllib3 warning writes to stderr. Repeating the full suite on OpenSSL-based Python 3.9.25 resolved those environment failures without source changes. The other supported runtimes and operating systems remain for CI.

November 11 branch refresh

Merged upstream 38d853bc into this branch in ce7047ca without rewriting history. Resolved the overlap with #1972 by applying configured timeout options to the thread-local curl returned by _get_curl(). Retained upstream's thread-isolation, concurrent-request, and close/reopen tests alongside all timeout regressions.

Fresh validation from an isolated worktree on Python 3.13.18:

  • pytest tests/test_http_client.py -n 0: 160 passed.
  • pytest -n 4: 4,467 passed, 7 skipped (351 warnings).
  • Scoped flake8 and Ruff format checks: passed.
  • git diff --check: passed.

The initial test invocation could not connect to stripe-mock; tests passed after starting stripe-mock 0.206.0 with the pinned spec/fixtures. These results are local, not GitHub CI approval.

PycurlClient hardcoded CONNECTTIMEOUT=30 and TIMEOUT=80 on every request,
unlike RequestsClient, HTTPXClient and AIOHTTPClient, which accept a
`timeout` constructor argument. Add keyword-only `timeout` and
`connect_timeout` arguments (defaults 80 and 30) after the existing
parameters so positional callers are unaffected.

Fixes stripe#1962
@itsrayeedscodespace
itsrayeedscodespace requested a review from a team as a code owner November 11, 2026 18:44
@itsrayeedscodespace
itsrayeedscodespace requested review from ramya-stripe and removed request for a team November 11, 2026 18:44
@cla-assistant

cla-assistant Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cla-assistant

cla-assistant Bot commented Nov 11, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Comment thread stripe/_http_client.py Resolved
@mark-kogan-stripe
mark-kogan-stripe enabled auto-merge (squash) November 13, 2026 16:38
@mark-kogan-stripe

Copy link
Copy Markdown
Contributor

Looks Good! Thank you for the submission

@mark-kogan-stripe
mark-kogan-stripe merged commit 7254286 into stripe:master Nov 13, 2026
17 checks passed
@itsrayeedscodespace

Copy link
Copy Markdown
Contributor Author

thanks @mark-kogan-stripe and @ramya-stripe. if you guys are taking in interns for your team, please let me know and/or i'd appreciate it if you could give me a recruiter contact. i'm a super eager cs major at georgia tech and i really believe i could contribute to your team. please lmk about any openings :)

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.

PycurlClient: allow configuring the connect and request timeouts (hardcoded to 30s / 80s)

2 participants