diff --git a/command/daemon.go b/command/daemon.go index fce08db6e..85a475732 100644 --- a/command/daemon.go +++ b/command/daemon.go @@ -698,12 +698,20 @@ func createDatastore(ctx context.Context, dir, dsType string) (datastore.Batchin } func cleanupTempData(ctx context.Context, ds datastore.Batching) error { - count, err := deletePrefix(ctx, ds, "/data-transfer-v2") + const dtCleanupTimeout = 10 * time.Minute + const dtPrefix = "/data-transfer-v2" + + ctx, cancel := context.WithTimeout(ctx, dtCleanupTimeout) + defer cancel() + + count, err := deletePrefix(ctx, ds, dtPrefix) if err != nil { + if errors.Is(err, context.DeadlineExceeded) { + log.Info("Not enough time to finish data-transfer state cleanup") + return ds.Sync(context.Background(), datastore.NewKey(dtPrefix)) + } return err } - if count != 0 { - log.Infow("Removed old temporary data-transfer fsm records", "count", count) - } + log.Infow("Removed old temporary data-transfer fsm records", "count", count) return nil }