Repository navigation
feat(low-code): opt-in TCP keepalive and request timeouts on HttpRequester #1168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
889a39b
feat(http): add default connect/read timeouts to HttpClient and make …
ZaneHyattAB 0638337
docs(http): describe request_timeout in HttpClient docstring
ZaneHyattAB 64c851b
fix(http): apply default request timeout to auth and unstructured-par…
ZaneHyattAB 5353132
fix(http): remove unused timeout re-exports
ZaneHyattAB 115bd5e
Merge origin/main into devin/1789662799-http-client-timeouts
ZaneHyattAB 0c915f3
fix(file-based): bound only the connect phase of the Unstructured API…
ZaneHyattAB 47fe300
Merge main into devin/1789662799-http-client-timeouts
ZaneHyattAB 20ec792
refactor(http): drop timeout env var overrides, keep fixed defaults
ZaneHyattAB 02ce04b
Merge main into devin/1789662799-http-client-timeouts
ZaneHyattAB eae8239
Merge main into devin/1789662799-http-client-timeouts
ZaneHyattAB 89da05e
Merge remote-tracking branch 'origin/main' into devin/1789662799-http…
ZaneHyattAB d7ea733
revert(http): remove fleet-wide default timeouts
ZaneHyattAB 5379652
feat(low-code): opt-in TCP keepalive and request timeouts on HttpRequ…
ZaneHyattAB df2201c
fix(http): declare urllib3 as a direct dependency for deptry
ZaneHyattAB 18ecc57
fix(deps): relock with Poetry 2.1.4 to avoid unrelated lockfile churn
ZaneHyattAB fdd9766
Merge remote-tracking branch 'origin/main' into devin/1789662799-http…
ZaneHyattAB a8e017c
fix(http): warn when TCP keepalive is unavailable; note read timeouts…
ZaneHyattAB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| # | ||
| # Copyright (c) 2026 Airbyte, Inc., all rights reserved. | ||
| # | ||
|
|
||
| import functools | ||
| import logging | ||
| import socket | ||
| from typing import List, Tuple, cast | ||
|
|
||
| import requests | ||
| import urllib3.connection | ||
|
|
||
| TCP_KEEPALIVE_IDLE_SECONDS = 60 | ||
| TCP_KEEPALIVE_INTERVAL_SECONDS = 10 | ||
| TCP_KEEPALIVE_PROBE_COUNT = 6 | ||
|
|
||
| logger = logging.getLogger("airbyte") | ||
|
|
||
|
|
||
| @functools.lru_cache(maxsize=None) | ||
| def tcp_keepalive_socket_options() -> Tuple[Tuple[int, int, int], ...]: | ||
| """Socket options enabling TCP keepalive, probed for what this OS supports. | ||
|
|
||
| Returns urllib3's default options plus SO_KEEPALIVE and the platform's idle / | ||
| interval / probe-count tuning options (TCP_KEEPIDLE on Linux/Windows, | ||
| TCP_KEEPALIVE on macOS). Each option is tried once on a throwaway socket and | ||
| dropped if the OS rejects it, because urllib3 applies these at connect time | ||
| and an unsupported option would fail every connection. Never raises. | ||
| """ | ||
| base_options = cast( | ||
| List[Tuple[int, int, int]], | ||
| list(urllib3.connection.HTTPConnection.default_socket_options), | ||
| ) | ||
|
|
||
| idle_option = getattr(socket, "TCP_KEEPIDLE", None) or getattr(socket, "TCP_KEEPALIVE", None) | ||
| candidates: List[Tuple[int, int, int]] = [ | ||
| (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1), | ||
| ] | ||
| if idle_option is not None: | ||
| candidates.append((socket.IPPROTO_TCP, idle_option, TCP_KEEPALIVE_IDLE_SECONDS)) | ||
| for name, value in ( | ||
| ("TCP_KEEPINTVL", TCP_KEEPALIVE_INTERVAL_SECONDS), | ||
| ("TCP_KEEPCNT", TCP_KEEPALIVE_PROBE_COUNT), | ||
| ): | ||
| option = getattr(socket, name, None) | ||
| if option is not None: | ||
| candidates.append((socket.IPPROTO_TCP, option, value)) | ||
|
|
||
| try: | ||
| probe = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
|
ZaneHyattAB marked this conversation as resolved.
|
||
| except OSError as error: | ||
| _warn_keepalive_unavailable(error) | ||
| return tuple(base_options) | ||
| try: | ||
| supported = base_options | ||
| for level, optname, value in candidates: | ||
| try: | ||
| probe.setsockopt(level, optname, value) | ||
| except OSError as error: | ||
| if (level, optname) == (socket.SOL_SOCKET, socket.SO_KEEPALIVE): | ||
| # Without SO_KEEPALIVE the tuning options are useless. | ||
| _warn_keepalive_unavailable(error) | ||
| return tuple(base_options) | ||
| continue | ||
| supported.append((level, optname, value)) | ||
| return tuple(supported) | ||
| finally: | ||
| probe.close() | ||
|
|
||
|
|
||
| def _warn_keepalive_unavailable(error: OSError) -> None: | ||
| # Logged once per process because tcp_keepalive_socket_options() is cached. | ||
| logger.warning( | ||
| "TCP keepalive is unavailable on this platform, so connections use plain sockets: %s", error | ||
| ) | ||
|
|
||
|
|
||
| class TcpKeepaliveHTTPAdapter(requests.adapters.HTTPAdapter): | ||
| """HTTPAdapter that enables TCP keepalive on every connection it pools.""" | ||
|
|
||
| def init_poolmanager(self, *args, **pool_kwargs): # type: ignore[no-untyped-def] | ||
| pool_kwargs.setdefault("socket_options", tcp_keepalive_socket_options()) | ||
| super().init_poolmanager(*args, **pool_kwargs) # type: ignore[no-untyped-call] | ||
|
|
||
| def proxy_manager_for(self, proxy, **proxy_kwargs): # type: ignore[no-untyped-def] | ||
| # requests does not forward init_poolmanager kwargs to proxy managers, | ||
| # so without this override proxied connections get no keepalive. | ||
| proxy_kwargs.setdefault("socket_options", tcp_keepalive_socket_options()) | ||
| return super().proxy_manager_for(proxy, **proxy_kwargs) # type: ignore[no-untyped-call] | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.