Skip to content

Updates in default connection and retry settings#4082

Open
petyaslavova wants to merge 14 commits into
masterfrom
ps_default_values_updates
Open

Updates in default connection and retry settings#4082
petyaslavova wants to merge 14 commits into
masterfrom
ps_default_values_updates

Conversation

@petyaslavova
Copy link
Copy Markdown
Collaborator

@petyaslavova petyaslavova commented May 27, 2026

Connection configs

This PR updates the default connection behavior for redis-py clients.
TCP keepalive is now enabled by default, and unspecified keepalive options resolve to platform-supported defaults: 30s idle, 5s interval, and 3 probes. The default socket timeout and socket connect timeout are now both 5 seconds.

The default socket read buffer size is reduced to 32kB, and the default connection pool limit is reduced from the previous effectively-unbounded value to 100 connections.
These defaults are applied across sync and async connection paths, with async cluster connection limits aligned as well.

Retry configs

The default retry policy now uses ExponentialWithJitterBackoff(base=0.01, cap=1) with 10 retries.
This gives standalone retry paths a 10ms base backoff, a 1000ms cap, and more retry attempts before surfacing retryable failures.

Cluster retry defaults are aligned to 10 attempts as well. For regular cluster commands, the retry object is still primarily used as a retry-count container, allowing more topology recovery attempts; cluster transactions use the full retry object and therefore honor the jittered backoff configuration.

Fixes #2243 and #2220


Note

High Risk
Changing library-wide defaults for timeouts, pooling, keepalive, and retry counts can break deployments that implicitly relied on unbounded waits, huge pools, or fewer retries—behavior shifts without code changes at call sites.

Overview
This PR changes default client behavior for new Redis, async, cluster, multidb, and HTTP clients when callers do not override settings.

Connections: Default socket_timeout and socket_connect_timeout are now 5 seconds (was often unlimited/None). TCP keepalive is on by default, with socket_keepalive_options resolving to platform-supported values (30s idle, 5s interval, 3 probes) unless None/{} is passed. Parser read buffer defaults drop from 64KiB to 32KiB. Connection pool and async cluster per-node max_connections default to 100 instead of an effectively unbounded value.

Retries: Default policy becomes Retry(ExponentialWithJitterBackoff(base=0.01, cap=1), retries=10) (was base=1, cap=10, 3 retries). Cluster cluster_error_retry_attempts defaults to 10; docs and examples are updated to match.

Internals: Shared defaults live in redis/_defaults.py; the omitted-argument SENTINEL is consolidated under redis.utils (parsers/async connection stop defining their own). Tests add tests/test_defaults.py and adjust maintenance/cluster tests for the new timeout and retry expectations.

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

@petyaslavova petyaslavova added the breakingchange API or Breaking Change label May 27, 2026
@jit-ci
Copy link
Copy Markdown

jit-ci Bot commented May 27, 2026

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

@petyaslavova petyaslavova force-pushed the ps_default_values_updates branch from 654a9fc to 82cedf2 Compare May 27, 2026 11:51
@petyaslavova petyaslavova marked this pull request as ready for review May 27, 2026 11:52
Comment thread redis/connection.py
Comment thread redis/asyncio/cluster.py
…r and max_connections in pool some test configs needed to be updated
Comment thread tests/test_cluster_transaction.py
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit aeb2e4b. Configure here.

Comment thread redis/client.py Outdated
Copy link
Copy Markdown
Collaborator

@elena-kolevska elena-kolevska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we extract the creation of a

Comment thread redis/_defaults.py
return options


# Retry defaults
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this wasn't finished. We have the default retry object instantiated in too many palces with magic number. Let's centralise it with some kind of a get_default_retry() factory.

Comment thread redis/_defaults.py

# Connection defaults

DEFAULT_SOCKET_TIMEOUT = 5
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this affect blocking commands? Do we dynamically change/disable the socket timeout on those connections?

decode_responses: bool = False,
parser_class: Type[BaseParser] = DefaultParser,
socket_read_size: int = 65536,
socket_read_size: int = 32768,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this should be configurable on the Client level, because it can be problematic for users with huge keys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breakingchange API or Breaking Change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

process hangs due to default socket_timeout=None

2 participants