-
Notifications
You must be signed in to change notification settings - Fork 140
fix race condition #7689
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
base: main
Are you sure you want to change the base?
fix race condition #7689
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a data race condition in the BLIP testing client where a shallow copy of the Hybrid Logical Vector (HLV) was being shared across goroutines. The race occurred when one goroutine was reading the HLV for logging purposes while another was modifying it, leading to concurrent map access violations.
- Updates the
_proposeChangesEntryForDoc
method to create a deep copy of the HLV instead of a shallow copy
@@ -295,7 +295,7 @@ func (cd *clientDoc) _proposeChangesEntryForDoc() *proposeChangeBatchEntry { | |||
} | |||
revTreeIDHistory = append(revTreeIDHistory, cd._revisionsBySeq[seq].version.RevTreeID) | |||
} | |||
return &proposeChangeBatchEntry{docID: cd.id, version: latestRev.version, revTreeIDHistory: revTreeIDHistory, hlvHistory: latestRev.HLV, latestServerVersion: cd._latestServerVersion, seq: cd._latestSeq, isDelete: latestRev.isDelete} | |||
return &proposeChangeBatchEntry{docID: cd.id, version: latestRev.version, revTreeIDHistory: revTreeIDHistory, hlvHistory: *latestRev.HLV.Copy(), latestServerVersion: cd._latestServerVersion, seq: cd._latestSeq, isDelete: latestRev.isDelete} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dereferencing of latestRev.HLV.Copy()
could lead to a panic if latestRev.HLV
is nil. Consider adding a nil check or ensuring Copy()
returns a non-nil pointer.
return &proposeChangeBatchEntry{docID: cd.id, version: latestRev.version, revTreeIDHistory: revTreeIDHistory, hlvHistory: *latestRev.HLV.Copy(), latestServerVersion: cd._latestServerVersion, seq: cd._latestSeq, isDelete: latestRev.isDelete} | |
var hlvCopy db.HybridLogicalVector | |
if latestRev.HLV != nil { | |
hlvCopy = *latestRev.HLV.Copy() | |
} else { | |
hlvCopy = *db.NewHybridLogicalVector() | |
} | |
return &proposeChangeBatchEntry{ | |
docID: cd.id, | |
version: latestRev.version, | |
revTreeIDHistory: revTreeIDHistory, | |
hlvHistory: hlvCopy, | |
latestServerVersion: cd._latestServerVersion, | |
seq: cd._latestSeq, | |
isDelete: latestRev.isDelete, | |
} |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is is necessary for testing.
Fixes data race since the HLV was a shallow copy: