fix(Redis): use shared_ptr for NotificationCenter, harden AsyncNotificationCenter::stop() - #5284
Merged
Merged
Conversation
aleks-f
requested changes
Apr 1, 2026
aleks-f
left a comment
Member
There was a problem hiding this comment.
Client may delete the pointer, leaving holders with a false ownership of a dangling pointer. It was a quick and dirty temporary hack until c++20 and atomic shared_ptr becomes available everywhere, but not a good idea really.
Proper solution is to use shared_ptr internally, protect it with mutex when atomic shared_ptr is not available.
…cationCenter::stop() Use shared_ptr internally in Redis::Client for the AsyncNotificationCenter. When std::atomic<shared_ptr> is available (C++20), use it directly; otherwise protect the shared_ptr with a mutex. This replaces the raw-pointer-with-no-op-deleter approach that could leave callers with dangling pointers if the Client was destroyed first. Also harden AsyncNotificationCenter::stop() to unconditionally wait for and join the dequeue thread, add missing connection guard to RedisTest::testPool, and enable Redis tests in the windows-2025-msvc-cmake CI job.
matejk
force-pushed
the
fix/redis-atomic-shared-ptr
branch
from
April 1, 2026 13:37
f2b227e to
803aa28
Compare
Contributor
Author
Applied requested changes. |
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.
Summary
shared_ptrinternally inRedis::Clientfor theAsyncNotificationCenter. Whenstd::atomic<shared_ptr>is available (C++20__cpp_lib_atomic_shared_ptr), use it directly; otherwise protect theshared_ptrwith astd::mutex. This replaces the raw-pointer-with-no-op-deleter approach that could leave callers with dangling pointers if theClientwas destroyed first.AsyncNotificationCenter::stop()to unconditionally wait for and join the dequeue thread, preventing potential issues ifstop()is called after the thread has already exited.RedisTest::testPool.windows-2025-msvc-cmakeCI job.Test plan
AsyncNotificationCenterTestpasses (14 tests)