fix: close pubsub connection on Subscribe error in CancelationPubSub#1104
Open
Bahtya wants to merge 2 commits intohibiken:masterfrom
Open
fix: close pubsub connection on Subscribe error in CancelationPubSub#1104Bahtya wants to merge 2 commits intohibiken:masterfrom
Bahtya wants to merge 2 commits intohibiken:masterfrom
Conversation
When redis.Subscribe succeeds but Receive() fails, the pubsub connection was not being closed before returning the error. This caused the subscriber goroutine to leak a Redis connection on each retry iteration, eventually exhausting the connection pool. Fixes hibiken#1095
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1104 +/- ##
==========================================
- Coverage 63.34% 63.32% -0.02%
==========================================
Files 29 29
Lines 4984 4985 +1
==========================================
Hits 3157 3157
- Misses 1549 1550 +1
Partials 278 278 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add TestCancelationPubSubReceiveError to verify that when Receive() fails in CancelationPubSub(), an error is returned and the pubsub connection is not leaked. This provides test coverage for the pubsub.Close() fix that was missing in the previous commit. Bahtya
Author
|
Friendly ping on this PR. The fix correctly closes the pubsub connection in the |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Fixes #1095
When
CancelationPubSub()ininternal/rdb/rdb.gocallsredis.Subscribefollowed byReceive(), andReceive()fails, thepubsubobject is not closed before returning the error. This causes a Redis connection leak.The subscriber goroutine (
subscriber.go) retries in an infinite loop on error, so each failed iteration leaks a new Redis connection. Over time, this exhausts the connection pool.Fix
Add
pubsub.Close()before the error return inCancelationPubSub():This is a minimal, targeted fix that ensures the pubsub connection is always cleaned up when
Receive()fails.Testing
go build ./...passesgo vet ./internal/rdb/passesThis PR was created by an AI contributor. The fix has been verified with build and vet checks.