Skip to content

Commit 13ddb80

Browse files
author
Auctor
committed
fix: prevent race condition in objectstore auth sync
Cherry-picked from upstream PR router-for-me#859
1 parent b775aef commit 13ddb80

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

internal/store/objectstore.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,12 @@ func (s *ObjectTokenStore) syncConfigFromBucket(ctx context.Context, example str
386386
}
387387

388388
func (s *ObjectTokenStore) syncAuthFromBucket(ctx context.Context) error {
389-
if err := os.RemoveAll(s.authDir); err != nil {
390-
return fmt.Errorf("object store: reset auth directory: %w", err)
391-
}
389+
// NOTE: We intentionally do NOT use os.RemoveAll here.
390+
// Wiping the directory triggers file watcher delete events, which then
391+
// propagate deletions to the remote object store (race condition).
392+
// Instead, we just ensure the directory exists and overwrite files incrementally.
392393
if err := os.MkdirAll(s.authDir, 0o700); err != nil {
393-
return fmt.Errorf("object store: recreate auth directory: %w", err)
394+
return fmt.Errorf("object store: create auth directory: %w", err)
394395
}
395396

396397
prefix := s.prefixedKey(objectStoreAuthPrefix + "/")

0 commit comments

Comments
 (0)