Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NRG: Fix data race in processAppendEntry #5970

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions server/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -3547,13 +3547,17 @@ func (n *raft) processAppendEntry(ae *appendEntry, sub *subscription) {
}
}

// Make a copy of these values, as the AppendEntry might be cached and returned to the pool in applyCommit.
aeCommit := ae.commit
aeReply := ae.reply

// Apply anything we need here.
if ae.commit > n.commit {
if aeCommit > n.commit {
if n.paused {
n.hcommit = ae.commit
n.debug("Paused, not applying %d", ae.commit)
n.hcommit = aeCommit
n.debug("Paused, not applying %d", aeCommit)
} else {
for index := n.commit + 1; index <= ae.commit; index++ {
for index := n.commit + 1; index <= aeCommit; index++ {
if err := n.applyCommit(index); err != nil {
break
}
Expand All @@ -3569,7 +3573,7 @@ func (n *raft) processAppendEntry(ae *appendEntry, sub *subscription) {

// Success. Send our response.
if ar != nil {
n.sendRPC(ae.reply, _EMPTY_, ar.encode(arbuf))
n.sendRPC(aeReply, _EMPTY_, ar.encode(arbuf))
arPool.Put(ar)
}
}
Expand Down