accounts: retry account renaming to avoid sync races

This commit is contained in:
Péter Szilágyi 2016-11-10 13:55:57 +02:00
parent 80ea44c485
commit 3980d3bf47
No known key found for this signature in database
GPG key ID: 119A76381CCB7DD2

View file

@ -207,8 +207,14 @@ func writeKeyFile(file string, content []byte) error {
return err
}
f.Close()
if err := os.Rename(f.Name(), file); err != nil {
// Renaming failed, may be a data race between a cache sync, retry
time.Sleep(100 * time.Millisecond)
return os.Rename(f.Name(), file)
}
return nil
}
// keyFileName implements the naming convention for keyfiles:
// UTC--<created_at UTC ISO8601>-<address hex>