mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-02 20:40:52 +08:00
Merge pull request #859 from shunkakinoki/fix/objectstore-sync-race-condition
fix: prevent race condition in objectstore auth sync
This commit is contained in:
@@ -386,11 +386,12 @@ func (s *ObjectTokenStore) syncConfigFromBucket(ctx context.Context, example str
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *ObjectTokenStore) syncAuthFromBucket(ctx context.Context) error {
|
func (s *ObjectTokenStore) syncAuthFromBucket(ctx context.Context) error {
|
||||||
if err := os.RemoveAll(s.authDir); err != nil {
|
// NOTE: We intentionally do NOT use os.RemoveAll here.
|
||||||
return fmt.Errorf("object store: reset auth directory: %w", err)
|
// Wiping the directory triggers file watcher delete events, which then
|
||||||
}
|
// propagate deletions to the remote object store (race condition).
|
||||||
|
// Instead, we just ensure the directory exists and overwrite files incrementally.
|
||||||
if err := os.MkdirAll(s.authDir, 0o700); err != nil {
|
if err := os.MkdirAll(s.authDir, 0o700); err != nil {
|
||||||
return fmt.Errorf("object store: recreate auth directory: %w", err)
|
return fmt.Errorf("object store: create auth directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
prefix := s.prefixedKey(objectStoreAuthPrefix + "/")
|
prefix := s.prefixedKey(objectStoreAuthPrefix + "/")
|
||||||
|
|||||||
Reference in New Issue
Block a user