NRG: Decouple Raft transport layer#8181
Conversation
f3a15ab to
106a8cf
Compare
|
Verified that there are no additional per message allocations using this benchmark: Without refactoring: With refactoring: The benchmark is not included in the PR, maybe not worth keeping. |
MauriceVanVeen
left a comment
There was a problem hiding this comment.
There seems to be a nil deref
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0xfc62be]
goroutine 92605 [running]:
github.com/nats-io/nats-server/v2/server.(*raft).GetTrafficAccountName(0xc003a43c08)
/home/runner/work/nats-server/nats-server/server/raft.go:667 +0x9e
106a8cf to
627ea0e
Compare
Fixed. |
|
@claude review |
|
Claude finished @sciascid's task in 3m 10s —— View job Code Review
Overall this is a clean, well-structured refactor. The 1.
|
627ea0e to
beae436
Compare
The Raft implementation was tightly coupled to the server's internal client and send queue for Raft RPC communication. This made it difficult to test scenarios such as network partitions deterministically. Introduce a raftTransport abstraction and keep the existing internal client/send queue behavior as the default transport. Tests can now inject a mock transport to simulate partitions and observe message delivery. Signed-off-by: Daniele Sciascia <daniele@nats.io>
beae436 to
1f992f5
Compare
|
|
Claude finished @sciascid's task in 1m 20s —— View job Response to feedback
Thanks for the clarifications and the rebase. All four points check out: 1. 2. Hub lock held during subscription callbacks 3. 4. The PR looks good. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1f992f5cf8
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if factory == nil { | ||
| factory = defaultRaftTransport | ||
| } | ||
| n.t = factory(s, n) |
There was a problem hiding this comment.
Reject nil raft transport from factory
After assigning n.t = factory(s, n), initialization proceeds into RecreateInternalSubs, which calls methods on n.t (for example Account, Reset, and later Publish) without a nil guard. If a custom RaftConfig.Transport factory returns nil (a realistic mistake when injecting test transports), startup will panic instead of returning a regular init error, making failures harder to diagnose and recover from.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Providing a custom factory is for testing only, so there's not much risk in that. Should a factory method returnsnil, it means that it needs to be fixed.
The Raft implementation was tightly coupled to the server's internal client and send queue for Raft RPC communication. This made it difficult to test scenarios such as network partitions deterministically.
Introduce a raftTransport abstraction and keep the existing internal client/send queue behavior as the default transport. Tests can now inject a mock transport to simulate partitions and observe message delivery.