Skip to content

Conversation

peteski22
Copy link
Contributor

@peteski22 peteski22 commented Sep 26, 2025

Summary

  • Add atomic flag coordination between SIGHUP signal handler and main reload loop
  • Prevent race condition where subsequent SIGHUP signals would be ignored after first reload
  • Add comprehensive test suite with stress testing for concurrent signal handling

Changes

  • Add reloadState type with atomic flag to coordinate reload operations
  • Update handleSignals to use atomic CompareAndSwap for thread safety
  • Ensure reload flag is properly reset after completion
  • Add new test cases covering edge cases and concurrent scenarios

Testing

Race condition testing shows no issues with concurrent access:

go test -race -count=100 ./cmd -run "TestDaemon_DaemonCmd_HandleSignals"                         
ok      github.com/mozilla-ai/mcpd/v2/cmd    76.651s

go test -race -count=100 ./cmd -run "TestDaemon_ReloadFlagManagement"                          
ok      github.com/mozilla-ai/mcpd/v2/cmd    54.903s

@peteski22 peteski22 force-pushed the peteski22/daemon/fix-race-signalhandling branch from c875e0c to 6d692ea Compare September 26, 2025 09:57
* Add reloadState type with atomic flag to coordinate between signal handler and main loop
* Prevent duplicate SIGHUP signals from triggering overlapping reloads
* Reset reload flag after completion to allow subsequent reloads
* Add comprehensive test suite covering concurrent signals and edge cases
* Update signal handler to use atomic CompareAndSwap for thread safety
@peteski22 peteski22 force-pushed the peteski22/daemon/fix-race-signalhandling branch from 6d692ea to 3afed93 Compare September 26, 2025 09:58
@peteski22 peteski22 added the bug Something isn't working label Sep 26, 2025
@peteski22 peteski22 merged commit 4eb0668 into main Oct 7, 2025
2 checks passed
@peteski22 peteski22 deleted the peteski22/daemon/fix-race-signalhandling branch October 7, 2025 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants