Skip to content

Add TCP keepalive socket options#124

Open
hownowstephen wants to merge 1 commit intomainfrom
tcp-keepalive-rebased
Open

Add TCP keepalive socket options#124
hownowstephen wants to merge 1 commit intomainfrom
tcp-keepalive-rebased

Conversation

@hownowstephen
Copy link
Copy Markdown
Contributor

@hownowstephen hownowstephen commented May 8, 2026

Summary

  • Configure TCP keepalive on outbound HTTPS connections via a custom TCPKeepAliveHTTPAdapter
  • Sets SO_KEEPALIVE, TCP_KEEPIDLE (300s), and TCP_KEEPINTVL (60s) to match server-side configuration
  • Adds test verifying keepalive options are set on the adapter's pool manager

Based on #70 by @zaf, rebased onto current main. Closes #70.

Test plan

  • All 37 existing tests pass
  • New test_keepalive_socket_options_are_configured_on_adapter verifies options set correctly
  • Verify keepalive behavior in production environment

Note

Medium Risk
Changes the HTTP transport adapter used for all HTTPS requests, which can affect connection reuse and behavior across platforms (different socket options availability). Impact is limited to client networking settings and covered by a targeted unit test.

Overview
Enables TCP keepalive on all outbound HTTPS requests by replacing the default HTTPAdapter with a custom TCPKeepAliveHTTPAdapter that injects keepalive-related socket_options into both direct and proxy connection pools.

Adds configurable constants for keepalive timing (idle 300s, interval 60s) and a new test (test_keepalive_socket_options_are_configured_on_adapter) asserting the adapter preserves urllib3 defaults while adding the keepalive options when supported by the OS.

Reviewed by Cursor Bugbot for commit b4ebb98. Bugbot is set up for automated code reviews on this repo. Configure here.

Configure TCP keepalive on outbound HTTPS connections via a custom
TCPKeepAliveHTTPAdapter. Sets SO_KEEPALIVE, TCP_KEEPIDLE (300s), and
TCP_KEEPINTVL (60s) to match server-side configuration.

Based on #70 by @zaf, rebased onto current main.
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.

1 participant