ENG-55756 Fix data race in CloneForSummary#86
Open
and-bezzir wants to merge 1 commit into
Open
Conversation
…on for `Filters` accesses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a data race in
view.(*Statelet).CloneForSummarythat caused aSIGSEGV(nil pointer dereference) panic indatly-platform-production.During a read,
queryInBatchesshares one*Stateletbetween two concurrent goroutines:querySummary→CloneForSummary, which readsStatelet.FiltersqueryObjects→Build, which growsStatelet.FiltersviaAppendFilters(service/reader/sql.go)AppendFiltersmutates the slice underfiltersMu, butCloneForSummaryread it without the lock. Whenappendreallocated the backing array, the clone could observe a torn slice header (newlen+ stale/nilptr) and copy off a nil pointer, faulting ataddr=0x0.Observed in prod:
Changes
view/state.go— acquirefiltersMuaround theFiltersread inCloneForSummary. The mutex itself is still not copied.view/state_race_test.go— race tests driving the realCloneForSummary(read) andAppendFilters(write) on a sharedStatelet:TestStatelet_SummaryClone_Fixed_NoRace— passes under-race.TestStatelet_SummaryClone_Unsafe_ReproducesRace— reproduces the original race (skipped by default; gated behindREPRODUCE_STATELET_RACE=1).Test plan
go test -race -run TestStatelet_SummaryClone_Fixed_NoRace ./view/passesREPRODUCE_STATELET_RACE=1 go test -race -run TestStatelet_SummaryClone_Unsafe_ReproducesRace ./view/reports the data race (read in clone vs write inAppendFilters)go vet ./view/clean