fs: retry vss creation on VSS_E_SNAPSHOT_SET_IN_PROGRESS error

Depending on the change packages, the VSS tests from ./cmd/restic and
the fs package may overlap in time. This causes the snapshot creation to
fail. Add retries in that case.
This commit is contained in:
Michael Eischer 2024-11-30 16:07:18 +01:00
parent c5fb46da53
commit 5df6bf80b1

View file

@ -171,6 +171,11 @@ func (h HRESULT) Str() string {
return "UNKNOWN"
}
// Error implements the error interface
func (h HRESULT) Error() string {
return h.Str()
}
// VssError encapsulates errors returned from calling VSS api.
type vssError struct {
text string
@ -195,6 +200,11 @@ func (e *vssError) Error() string {
return fmt.Sprintf("VSS error: %s: %s (%#x)", e.text, e.hresult.Str(), e.hresult)
}
// Unwrap returns the underlying HRESULT error
func (e *vssError) Unwrap() error {
return e.hresult
}
// vssTextError encapsulates errors returned from calling VSS api.
type vssTextError struct {
text string
@ -943,10 +953,23 @@ func NewVssSnapshot(provider string,
"%s", volume))
}
snapshotSetID, err := iVssBackupComponents.StartSnapshotSet()
if err != nil {
iVssBackupComponents.Release()
return VssSnapshot{}, err
const retryStartSnapshotSetSleep = 5 * time.Second
var snapshotSetID ole.GUID
for {
var err error
snapshotSetID, err = iVssBackupComponents.StartSnapshotSet()
if errors.Is(err, VSS_E_SNAPSHOT_SET_IN_PROGRESS) && time.Now().Add(-retryStartSnapshotSetSleep).Before(deadline) {
// retry snapshot set creation while deadline is not reached
time.Sleep(retryStartSnapshotSetSleep)
continue
}
if err != nil {
iVssBackupComponents.Release()
return VssSnapshot{}, err
} else {
break
}
}
if err := iVssBackupComponents.AddToSnapshotSet(volume, providerID, &snapshotSetID); err != nil {