This is an automated email from the ASF dual-hosted git repository.
git-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 12fc17a75 fix(server): avoid ROLE crash when the DB is closed during
full sync (#3667)
12fc17a75 is described below
commit 12fc17a756e46bce39889177b8176467f24e67da
Author: jonas <[email protected]>
AuthorDate: Wed Oct 14 14:42:46 2026 +0800
fix(server): avoid ROLE crash when the DB is closed during full sync (#3667)
This closes #3666
## Summary
`ROLE` is registered with `ok-loading`, so it runs while the server is
loading. During a full sync, `Server::PrepareRestoreDB()` closes the DB
(`db_ = nullptr`) and only reopens it after the checkpoint is restored.
Any `ROLE` executed in this window dereferences the null `db_` in
`Storage::LatestSeqNumber()` and the process dies with SIGSEGV.
## Fix
Align `ROLE` with `INFO`: in the slave branch of `GetRoleInfo()`, skip
reading the sequence number while `is_loading_` is set and report the
offset as `0`.
## AI Usage Disclosure
- The coredump analysis and the fix were implemented manually.
- AI tools (Kimi K3) were used to assist in code review; all review
suggestions were checked by the author.
Co-authored-by: Twice <[email protected]>
---
src/server/server.cc | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/server/server.cc b/src/server/server.cc
index cbb7bd120..7842c5a81 100644
--- a/src/server/server.cc
+++ b/src/server/server.cc
@@ -1335,7 +1335,11 @@ std::string Server::GetRoleInfo() {
} else {
roles.emplace_back("connecting");
}
- roles.emplace_back(std::to_string(storage->LatestSeqNumber()));
+ std::string latest_seq_str = "0";
+ if (!is_loading_) {
+ latest_seq_str = std::to_string(storage->LatestSeqNumber());
+ }
+ roles.emplace_back(latest_seq_str);
return redis::ArrayOfBulkStrings(roles);
} else {
std::vector<std::string> list;