Fix node certificate synchronization - #8135
Conversation
Protect mutable node certificates with a dedicated mutex and use stable copies outside the lock. Make NodeClient own immutable certificate snapshots so retired-node cleanup cannot race certificate renewal.\n\nAddresses item 3 of #8123. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR improves node certificate synchronization in NodeState by separating certificate mutation from the broad NodeState::lock, publishing stable certificate snapshots under a dedicated mutex, and ensuring asynchronous internal RPC users (NodeClient) retain immutable certificate copies to avoid races during renewal.
Changes:
- Introduce a dedicated
node_certificates_lockinNodeStateand use it to protect reads/writes of mutable node certificate state. - Change
NodeClient/HTTPNodeClientto store certificate snapshots by value (immutable) instead of references intoNodeState. - Add a focused unit test (
node_client_test) and update recovery-decision-protocol certificate readers to use stable snapshot access.
Custom instructions used:
.github/copilot-instructions.md.github/instructions/reviewing.instructions.md
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/node/node_state.h |
Adds a dedicated certificate mutex, narrows certificate lock scopes, and passes stable certificate snapshots to TLS/session setup and internal clients. |
src/node/node_client.h |
Switches certificate ownership from references to immutable by-value snapshots. |
src/node/http_node_client.h |
Updates constructor/ownership to pass certificate snapshots into the base NodeClient. |
src/node/recovery_decision_protocol.cpp |
Uses NodeState certificate snapshot accessor and avoids holding broad locks while preparing authenticated messages. |
src/node/test/node_client.cpp |
Adds a unit test verifying NodeClient retains certificate snapshots after source mutation. |
CMakeLists.txt |
Registers the new node_client_test unit test target. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Max (maxtropets)
left a comment
There was a problem hiding this comment.
LGTM, but I'd say Eddy should have a look, I'm not a lock-master
|
Eddy Ashton (@eddyashton) can you have a look please? |
Eddy Ashton (eddyashton)
left a comment
There was a problem hiding this comment.
If LONG_TEST (TSAN) is happy, I'm happy.
Summary
NodeClientown immutable certificate snapshots instead of references intoNodeStateIssue #8123 coverage
This PR resolves Still Applicable item 3, certificate state lock ordering and ownership:
NodeState::lockNodeClientusers retain immutable certificate snapshots rather than references that can race renewalThis PR does not resolve items 4-6 or the remaining AFT startup question.
Testing
node_client_test,ccf,loggingbuild-local/tests.sh -R '^node_client_test$'node_client_testandccfand reran the focused unit testPartially addresses #8123