You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by "jonasmao (via GitHub)" <gi...@apache.org> on 2026/10/10 13:04:46 UTC

[PR] Fix the ROLE command crash when the DB is closed during full sync [kvrocks]

jonasmao opened a new pull request, #3667:
URL: https://github.com/apache/kvrocks/pull/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`. 
   
   ```diff
   diff --git a/src/server/server.cc b/src/server/server.cc
   --- a/src/server/server.cc
   +++ b/src/server/server.cc
   @@ 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;
   ```
   
   ## 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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix the ROLE command crash when the DB is closed during full sync [kvrocks]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #3667:
URL: https://github.com/apache/kvrocks/pull/3667#issuecomment-6097797834

   Hi @jonasmao,
   
   Thank you for your pull request. Please review our [Contributing Guide](https://kvrocks.apache.org/community/contributing/).
   
   Please make sure you understand your changes and explain your reasoning in this pull request. Low-quality pull requests may be closed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(server): avoid ROLE crash when the DB is closed during full sync [kvrocks]

Posted by "git-hulk (via GitHub)" <gi...@apache.org>.
git-hulk merged PR #3667:
URL: https://github.com/apache/kvrocks/pull/3667


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(server): avoid ROLE crash when the DB is closed during full sync [kvrocks]

Posted by "jonasmao (via GitHub)" <gi...@apache.org>.
jonasmao commented on PR #3667:
URL: https://github.com/apache/kvrocks/pull/3667#issuecomment-6105001700

   > should this command just not be "ok-loading"? cc @git-hulk
   
   I think it needs to align with Redis based on this consideration: (#661)
   Monitoring and health checks: External clients and monitoring systems rely on ROLE cc @git-hulk


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(server): avoid ROLE crash when the DB is closed during full sync [kvrocks]

Posted by "git-hulk (via GitHub)" <gi...@apache.org>.
git-hulk commented on PR #3667:
URL: https://github.com/apache/kvrocks/pull/3667#issuecomment-6105198787

   @PragmaTwice @jonasmao As far as I know, only the `ROLE` command is used in replication tests(migrated from Redis test suites). It makes sense to have the `ROLE` command available during the restore process.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org