Skip to content

fix(Redis): use shared_ptr for NotificationCenter, harden AsyncNotificationCenter::stop() - #5284

Merged
matejk merged 1 commit into
mainfrom
fix/redis-atomic-shared-ptr
Apr 1, 2026
Merged

fix(Redis): use shared_ptr for NotificationCenter, harden AsyncNotificationCenter::stop()#5284
matejk merged 1 commit into
mainfrom
fix/redis-atomic-shared-ptr

Conversation

@matejk

@matejk matejk commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Use shared_ptr internally in Redis::Client for the AsyncNotificationCenter. When std::atomic<shared_ptr> is available (C++20 __cpp_lib_atomic_shared_ptr), use it directly; otherwise protect the shared_ptr with a std::mutex. This replaces the raw-pointer-with-no-op-deleter approach that could leave callers with dangling pointers if the Client was destroyed first.
  • Harden AsyncNotificationCenter::stop() to unconditionally wait for and join the dequeue thread, preventing potential issues if stop() is called after the thread has already exited.
  • Add missing connection guard to RedisTest::testPool.
  • Enable Redis tests in windows-2025-msvc-cmake CI job.

Test plan

  • Foundation AsyncNotificationCenterTest passes (14 tests)
  • Redis library and test runner build cleanly
  • Verify on Windows CI (Redis tests should skip gracefully without a server)

@matejk matejk added this to the Release 1.15.2 milestone Apr 1, 2026
@matejk matejk added the bug label Apr 1, 2026

@aleks-f aleks-f 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.

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
matejk force-pushed the fix/redis-atomic-shared-ptr branch from f2b227e to 803aa28 Compare April 1, 2026 13:37
@matejk matejk changed the title fix(Redis): remove POCO_HAVE_ATOMIC_SHARED_PTR, harden AsyncNotificationCenter::stop() fix(Redis): use shared_ptr for NotificationCenter, harden AsyncNotificationCenter::stop() Apr 1, 2026
@matejk

matejk commented Apr 1, 2026

Copy link
Copy Markdown
Contributor Author

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.

Applied requested changes.

@matejk
matejk requested a review from aleks-f April 1, 2026 13:40
@matejk
matejk merged commit dfb1f99 into main Apr 1, 2026
102 checks passed
@matejk
matejk deleted the fix/redis-atomic-shared-ptr branch April 1, 2026 20:25
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.

2 participants