Skip to content

replace context.TODO with context.WithTimeout in channel.initHealthCheck#3819

Merged
ndyakov merged 6 commits into
redis:masterfrom
abdellani:3811_fix_pubsub_health-check-ping
Jun 17, 2026
Merged

replace context.TODO with context.WithTimeout in channel.initHealthCheck#3819
ndyakov merged 6 commits into
redis:masterfrom
abdellani:3811_fix_pubsub_health-check-ping

Conversation

@abdellani

@abdellani abdellani commented May 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #3811


Note

Medium Risk
Changes reconnect behavior under slow or stuck Redis/network by capping ping and reconnect duration; mis-tuned timeouts could trigger reconnects sooner than before, but defaults are reasonable for a background health loop.

Overview
Fixes #3811 by making the background PubSub channel health-check goroutine use bounded deadlines instead of an unbounded context.TODO() for periodic Ping and for reconnect after a failed ping.

Adds WithChannelPingTimeout (default 5s) and WithChannelReconnectTimeout (default 10s) as ChannelOptions, stored on the internal channel struct. When the health-check timer fires, Ping runs under context.WithTimeout(..., pingTimeout); on failure, reconnect runs under a separate timeout (default 10s).

Also adjusts timer draining when a ping is received on the c.ping channel: it uses a non-blocking drain of timer.C instead of timer.Stop() plus blocking read, avoiding a possible block on the timer channel.

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

@jit-ci

jit-ci Bot commented May 20, 2026

Copy link
Copy Markdown

Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset.

In case there are security findings, they will be communicated to you as a comment inside the PR.

Hope you’ll enjoy using Jit.

Questions? Comments? Want to learn more? Get in touch with us.

Comment thread pubsub.go Outdated
@ndyakov

ndyakov commented May 21, 2026

Copy link
Copy Markdown
Member

Thank you @abdellani, Will review this as soon as possible.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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

Reviewed by Cursor Bugbot for commit 9f83adc. Configure here.

Comment thread pubsub.go
@abdellani
abdellani requested a review from ndyakov June 9, 2026 17:39
Comment thread pubsub.go
Comment thread pubsub.go Outdated
@abdellani
abdellani requested a review from ndyakov June 15, 2026 08:40

@ndyakov ndyakov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you @abdellani, looks good will double check and include tomorrow!

@ndyakov
ndyakov merged commit 1f0ea0e into redis:master Jun 17, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PubSub Channel health-check PING can block after Sentinel failover

2 participants