This is an automated email from the ASF dual-hosted git repository.

hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new da5e46307 fix(server): data race when accessing the db scan infos in 
GetLatestKeyNumStats (#3414)
da5e46307 is described below

commit da5e46307047b3e89753f0c9c02996430e758a5f
Author: Songqing Zhang <[email protected]>
AuthorDate: Wed Apr 1 22:07:01 2026 +0800

    fix(server): data race when accessing the db scan infos in 
GetLatestKeyNumStats (#3414)
    
    db_scan_infos_.find() was called without holding db_job_mu_, while
        background threads mutate the map under that lock. Acquire the lock
        before find() to match the pattern used in GetLastScanTime.
    
    Co-authored-by: hulk <[email protected]>
---
 src/server/server.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/server/server.cc b/src/server/server.cc
index cc1f5b677..fc763863b 100644
--- a/src/server/server.cc
+++ b/src/server/server.cc
@@ -1731,9 +1731,9 @@ Status Server::AsyncScanDBSize(const std::string &ns) {
 }
 
 void Server::GetLatestKeyNumStats(const std::string &ns, KeyNumStats *stats) {
+  std::lock_guard<std::mutex> lg(db_job_mu_);
   auto iter = db_scan_infos_.find(ns);
   if (iter != db_scan_infos_.end()) {
-    std::lock_guard<std::mutex> lg(db_job_mu_);
     *stats = iter->second.key_num_stats;
   }
 }

Reply via email to