Repository navigation
feat(http): let HttpStream opt in to TCP keepalive and request timeouts - #1273
Open
Kaizer (kaizerch) wants to merge 1 commit into
Open
Kaizer (kaizerch) wants to merge 1 commit into
Kaizer (kaizerch) wants to merge 1 commit into
Conversation
HttpStream builds its HttpClient without use_tcp_keepalive or request_timeout, so a Python connector could only get the protections #1168 added by mounting an adapter on the client's private session. Add two overridable properties, following use_cache: - use_tcp_keepalive (default False) mounts TcpKeepaliveHTTPAdapter on the stream's session, so a dropped connection fails in about two minutes instead of blocking a read forever; - request_timeout (default None) is sent with every request; a "timeout" from request_kwargs() still wins. Both are off by default, so existing connectors don't change.
👋 Greetings, Airbyte Team Member!Here are some helpful tips and reminders for your convenience. 💡 Show Tips and TricksTesting This CDK VersionYou can test this version of the CDK using the following: # Run the CLI from this branch:
uvx 'git+https://github.com/airbytehq/airbyte-python-cdk.git@kaizerch/feat/http-stream-tcp-keepalive-timeout#egg=airbyte-python-cdk[dev]' --help
# Update a connector to use the CDK from this branch ref:
cd airbyte-integrations/connectors/source-example
poe use-cdk-branch kaizerch/feat/http-stream-tcp-keepalive-timeoutPR Slash CommandsAirbyte Maintainers can execute the following slash commands on your PR:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
👉 TL;DR: Python connectors built on
HttpStreamcan now turn on TCP keepalive and request timeouts by overriding a property, the same way they turn onuse_cache. Both are off by default, so no existing connector changes.#1168 added opt-in keepalive and timeouts to
HttpRequester(low-code), butHttpStreambuilds itsHttpClientwithout them, andHttpClientnever modifies a session passed into it. So a Python connector can only get keepalive by mountingTcpKeepaliveHTTPAdapteron the client's private session, which is what source-salesforce does today (airbytehq/airbyte#91215).Tracks https://github.com/airbytehq/airbyte-internal-issues/issues/18622 (part 1).
Changes
HttpStream.use_tcp_keepalive(defaultFalse): whenTrue, the stream's session mountsTcpKeepaliveHTTPAdapter, so a dropped connection fails in about two minutes instead of blocking a read forever.HttpStream.request_timeout(defaultNone): a number or a(connect, read)pair sent with every request. Atimeoutreturned byrequest_kwargs()still takes precedence.HttpClientthatHttpStream.__init__builds.HttpClientalready supported both parameters.Review Spotlight
http.py#L54-L69: the two arguments passed intoHttpClient.http.py#L110-L124: the two properties.Risks
HttpClientused before. No connector in the airbyte monorepo defines arequest_timeoutoruse_tcp_keepaliveattribute that would now be picked up.HttpStream.__init__, so an override can't depend on attributes a subclass sets after callingsuper().__init__().use_cachealready works this way.Post-merge actions
7.48.0if nothing else lands first).use_tcp_keepalive = Trueand remove its hand-mounted adapter (built and tested locally against this branch).Test plan
test_http.py: a default stream mounts the plain adapter and sends no timeout; an opted-in stream mountsTcpKeepaliveHTTPAdapterand sends(30, 180); atimeoutfromrequest_kwargs()wins. With thehttp.pychange reverted, the two opted-in tests fail and the two others pass.unit_tests/sources/streams/http: 556 passed, 3 skipped.poetry run pytest unit_tests -m "not slow and not requires_creds": 6,454 passed, 39 skipped.ruff check,ruff format --checkandmypyonhttp.pypass.use_tcp_keepalive = Trueand its manual mount removed: its REST session still gets the keepalive adapter, and the full connector unit suite passes (SF_SUITE_RESULT).