Skip to content
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

ref(redis): Configure default 3s socket timeout #53513

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/sentry/utils/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@

logger = logging.getLogger(__name__)


_REDIS_DEFAULT_CLIENT_ARGS = {
# 3 seconds default socket and socket connection timeout avoids blocking on socket till the
# operating sysstem level timeout kicks in
"socket_timeout": 3.0
}

_pool_cache = {}
_pool_lock = Lock()

Expand Down Expand Up @@ -62,6 +69,10 @@ def factory(self, **config):
hosts = {k: v for k, v in enumerate(hosts)} if isinstance(hosts, list) else hosts
config["hosts"] = hosts

pool_options = config.pop("client_args", {})
pool_options = {**_REDIS_DEFAULT_CLIENT_ARGS, **pool_options}
config["pool_options"] = pool_options

return _make_rb_cluster(**config)

def __str__(self):
Expand Down Expand Up @@ -109,6 +120,7 @@ def factory(self, **config):
readonly_mode = config.get("readonly_mode", False)

client_args = config.get("client_args") or {}
client_args = {**_REDIS_DEFAULT_CLIENT_ARGS, **client_args}

# Redis cluster does not wait to attempt to connect. We'd prefer to not
# make TCP connections on boot. Wrap the client in a lazy proxy object.
Expand Down
Loading