Skip to content

Fix: Race conditions in move operations and improve installation#9

Merged
raythurman2386 merged 2 commits intomainfrom
bugfix/move-race-condition
Feb 28, 2026
Merged

Fix: Race conditions in move operations and improve installation#9
raythurman2386 merged 2 commits intomainfrom
bugfix/move-race-condition

Conversation

@raythurman2386
Copy link
Copy Markdown
Owner

This PR fixes race conditions in file move operations and improves installation to prevent multiple daemon instances.

Root cause: fsnotify fires multiple events for the same file (e.g., Create
then Write when a download completes, or the move triggering a Rename event).
The daemon was processing each event, causing duplicate move attempts.

Changes:
- Add 100ms event debouncing in watcher to coalesce rapid events for the
  same file path into a single event (internal/watcher/watcher.go)
- Add graceful handling in move: if source is already gone but exists at
  destination, treat as success (internal/actions/actions.go)
- Handle TOCTOU race: re-check source existence after a failed rename to
  catch files moved between stat and rename (internal/actions/actions.go)
- Add tests for move with already-moved source (internal/actions/actions_test.go)

This prevents false 'Action failed' error logs when files are moved
successfully but multiple fsnotify events fire for the same file.
Move operation fixes:
- Handle TOCTOU races: source disappearance at any point now returns success
- Simplify move() logic with renameOrSkip() helper
- Remove fragile stat checks that were themselves racy

Installation improvements:
- Makefile now stops running strawd before installing binaries
- install.sh (curl install): Stop existing instances before binary replacement
- install.sh: Properly handle fresh install vs upgrade with conditional start/restart
- install_service.sh: Stop service before updating, conditional start/restart

This ensures:
1. No false 'Action failed' errors when files are moved by duplicate events
2. Clean binary replacement without running multiple daemon instances
3. Proper service management on both fresh installs and upgrades
@raythurman2386 raythurman2386 merged commit 384583a into main Feb 28, 2026
4 checks passed
@raythurman2386 raythurman2386 deleted the bugfix/move-race-condition branch February 28, 2026 01:42
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.

1 participant