Skip to content

Issue #562 : Read the finalizer counter atomically - #563

Open
ViktorBystrov72 wants to merge 1 commit into
yuin:masterfrom
ViktorBystrov72:fix/finalizer-counter-race
Open

ViktorBystrov72 wants to merge 1 commit into
yuin:masterfrom
ViktorBystrov72:fix/finalizer-counter-race

Conversation

@ViktorBystrov72

Copy link
Copy Markdown

Fixes #562.

Changes proposed in this pull request:

  • Read the test finalizer counter with atomic.LoadInt32, matching its atomic updates.
  • Keep the existing finalizer test and its assertions unchanged. No production code is modified.

Validation:

  • The race reproduces on unchanged master with go test -race -run '^TestLocalVarFree$' -count=1 ..
  • The fixed test passes 30 race-enabled repetitions.
  • make build and the complete, unfiltered go test -race -count=1 ./... pass on Go 1.27.3; the full race suite also passes on Go 1.23.12.

The finalizer updates numActiveUserDatas with atomic.AddInt32. Use an
atomic load in countFinalizers too, so TestLocalVarFree does not race
with the runtime finalizer goroutine.

Signed-off-by: Виктор Быстров <anatema@bk.ru>
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.

TestLocalVarFree races when reading the finalizer counter

1 participant