Skip to content

Fix concurrent SetTags race on config.Tags - #836

Open
BetterAndBetterII wants to merge 1 commit into
hashicorp:masterfrom
BetterAndBetterII:fix/set-tags-race
Open

Fix concurrent SetTags race on config.Tags#836
BetterAndBetterII wants to merge 1 commit into
hashicorp:masterfrom
BetterAndBetterII:fix/set-tags-race

Conversation

@BetterAndBetterII

Copy link
Copy Markdown

Description

Serf.SetTags wrote config.Tags without synchronization even though the Serf godoc states that all methods are safe to call concurrently. Concurrent SetTags calls (and concurrent reads via NodeMeta / query tag filters) race on the tag map, and concurrent memberlist.UpdateNode calls can also race.

This change:

  • Protects config.Tags with tagsLock
  • Snapshots tags under the lock for NodeMeta and query tag filters
  • Serializes memberlist.UpdateNode from SetTags

Related Issue

Fixes #621

How Has This Been Tested?

go test -race -count=1 -timeout 90s -run 'TestSerf_SetTags$|TestSerf_SetTags_Concurrent' ./serf
go test -race -count=1 -timeout 120s ./serf

Added TestSerf_SetTags_Concurrent, which failed under -race before the lock and passes after.

Contributor Checklist

  • LLM Usage If an LLM was used to generate any code, please ensure and confirm you have read and followed the AI usage guide.

Serialize tag map updates under tagsLock, snapshot tags for NodeMeta and
query filters, and serialize memberlist.UpdateNode so concurrent SetTags
calls match the Serf concurrent-safety guarantee.
@BetterAndBetterII
BetterAndBetterII requested a review from a team as a code owner September 4, 2026 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Serf.SetTags can race with itself

1 participant