You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
redis: Use local shared_ptr copies to prevent race conditions
The previous fix with null checks still had a race condition window between
checking the pointer and using it. Even with the null check, the shared_ptr
could be reset to null by another thread between the check and use.
Solution: Make local copies of shared_ptr before use. This ensures the
pointer remains valid throughout its usage in the current scope.
Changes:
1. startResolveRedis(): Copy info_ to local variable before use
2. updateDnsStats(): Use local copy of info_
3. DNS callbacks: Use local copy for stats updates
4. onResponse(), onUnexpectedResponse(), onFailure(): Use local copies
5. client_factory_.create(): Check and use local copy of info_
The pattern applied:
auto info = parent_.info_; // Make local copy (ref count++)
if (!info) { // Check if null
return;
}
info->method(); // Safe to use - won't become null
This prevents the crash at line 376 where info_ was becoming null
between the check and the access, even with memory_order_acquire.
0 commit comments