Skip to content

Parse Config once when first used concurrently - #16

Merged
andrew merged 1 commit into
git-pkgs:mainfrom
simonchrz:fix/parse-race
Nov 2, 2026
Merged

andrew merged 1 commit into
git-pkgs:mainfrom
simonchrz:fix/parse-race

Conversation

@simonchrz

@simonchrz simonchrz commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Config.parse set parsed before it filled the durations, so a goroutine making a concurrent first call could see cooldown as off, or read the maps while another goroutine wrote them.

The parsing now runs through a sync.Once field, as suggested in the issue. The public API is unchanged. Config can no longer be copied after use without go vet flagging it, so TestConfigEnabled now holds *Config. The proxy only passes *cooldown.Config.

TestConfigConcurrentFirstUse makes eight concurrent first calls to For on a fresh Config. Without the fix the race detector reports the race, and even without -race some calls return the 3d default instead of the 7d npm duration.

Fixes #15.

parse set parsed before filling the durations, so a concurrent first
call could see cooldown as off or read the maps while they were
written. It now runs through a sync.Once.
@andrew
andrew merged commit 314a5f3 into git-pkgs:main Nov 2, 2026
2 checks passed
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.

Config.parse races on concurrent first use

2 participants