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

local: fixes a data race in anti-entropy sync #12324

Merged
merged 7 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions .changelog/12324.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
fix data race in TestAgentConfigWatcherSidecarProxy
rboyer marked this conversation as resolved.
Show resolved Hide resolved
```
16 changes: 16 additions & 0 deletions agent/local/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1083,12 +1083,21 @@ func (l *State) updateSyncState() error {
continue
}

wasCopied := false

// If our definition is different, we need to update it. Make a
// copy so that we don't retain a pointer to any actual state
// store info for in-memory RPCs.
if ls.Service.EnableTagOverride {
tags := make([]string, len(rs.Tags))
copy(tags, rs.Tags)

// Make a shallow copy since we're going to mutate it and other
// readers may be reading it and we want to avoid a race.
dup := *ls.Service
ls.Service = &dup
wasCopied = true

ls.Service.Tags = tags
}

Expand All @@ -1106,6 +1115,13 @@ func (l *State) updateSyncState() error {
m[k] = v
}
}
if !wasCopied {
// Make a shallow copy since we're going to mutate it and other
// readers may be reading it and we want to avoid a race.
wasCopied = true
rboyer marked this conversation as resolved.
Show resolved Hide resolved
dup := *ls.Service
ls.Service = &dup
}
ls.Service.TaggedAddresses = m
}
ls.InSync = ls.Service.IsSame(rs)
Expand Down