mirror of
https://github.com/turbot/steampipe.git
synced 2025-12-19 09:58:53 -05:00
* Add test demonstrating race condition in State.Save() Add TestStateFileRaceCondition which demonstrates the race condition that can occur when multiple goroutines call State.Save() concurrently. Without proper synchronization, concurrent writes to the same file can result in corrupted JSON. This test creates 50 concurrent goroutines each performing 20 Save() operations to increase the likelihood of exposing the race condition. Related to #4760 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix race condition in State.Save() with mutex and atomic write Protect State.Save() with a mutex to prevent concurrent writes from corrupting the state file. This fixes the race condition where multiple goroutines could write to the file simultaneously, resulting in invalid JSON. The fix uses: 1. A package-level mutex to serialize all Save() operations 2. Atomic write pattern (write to temp file, then rename) for additional safety against partial writes This ensures the state file remains valid even under high concurrency. Fixes #4760 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>