Skip to content

fix(config): make DefaultPaths() thread-safe with sync.Once#98

Merged
CalvinAllen merged 2 commits intomainfrom
fix/default-paths-thread-safe
Dec 11, 2025
Merged

fix(config): make DefaultPaths() thread-safe with sync.Once#98
CalvinAllen merged 2 commits intomainfrom
fix/default-paths-thread-safe

Conversation

@CalvinAllen
Copy link
Contributor

Summary

  • Use sync.Once to ensure paths are initialized exactly once
  • Eliminates race condition when called from multiple goroutines
  • Guarantees os.UserHomeDir() and filepath.Join() are called only once

Changes

src/internal/config/paths.go

  • Added sync.Once for thread-safe initialization
  • DefaultPaths() now uses pathsOnce.Do() instead of nil check

src/internal/config/paths_test.go

  • Added resetPathsForTesting() helper to reset singleton for test isolation
  • Added TestDefaultPaths_ConcurrentAccess test with 100 goroutines
  • Updated existing env var test to use new reset helper

Test plan

  • All existing tests pass
  • New concurrent access test passes
  • Race detector validates fix (requires cgo, tested in CI on Linux)

Closes #94

- Use sync.Once to ensure paths are initialized exactly once
- Eliminates race condition when called from multiple goroutines
- Add concurrent access test with 100 goroutines
- Add resetPathsForTesting() helper for test isolation

Closes #94
Add dedicated race detection job that runs Go tests with -race flag
on Linux (requires cgo). This validates thread-safety of concurrent
code like the sync.Once pattern used in DefaultPaths().

- Runs on ubuntu-latest where cgo is available
- Generates GitHub Actions summary with race detection results
- Build jobs now depend on race detection passing
- Extracts and displays race details if any are found

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@CalvinAllen CalvinAllen merged commit 92b4731 into main Dec 11, 2025
10 checks passed
@CalvinAllen CalvinAllen deleted the fix/default-paths-thread-safe branch December 11, 2025 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

fix(config): make DefaultPaths() thread-safe with sync.Once

1 participant