diff --git a/cmd/migrate-lid/migrate_lid.go b/cmd/migrate-lid/migrate_lid.go index b076599e6..df2035b6b 100644 --- a/cmd/migrate-lid/migrate_lid.go +++ b/cmd/migrate-lid/migrate_lid.go @@ -245,10 +245,17 @@ func migrateIndices(ctx context.Context, logger *zap.SugaredLogger, bar *progres start := time.Now() - indexed, err := migrateIndex(ctx, ipath, store, force) + timeoutCtx, timeoutCancel := context.WithTimeout(ctx, 60*time.Second) + defer timeoutCancel() + + indexed, err := migrateIndexWithTimeout(timeoutCtx, ipath, store, force) bar.Add(1) //nolint:errcheck if err != nil { - logger.Errorw("migrate index failed", "piece cid", ipath.name, "err", err) + took := time.Since(start) + indexTime += took + + logger.Errorw("migrate index failed", "piece cid", ipath.name, "took", took.String(), "err", err) + errCount++ continue } @@ -268,6 +275,32 @@ func migrateIndices(ctx context.Context, logger *zap.SugaredLogger, bar *progres return errCount, nil } +type migrateIndexResult struct { + Indexed bool + Error error +} + +func migrateIndexWithTimeout(ctx context.Context, ipath idxPath, store StoreMigrationApi, force bool) (bool, error) { + result := make(chan migrateIndexResult, 1) + go func() { + result <- doMigrateIndex(ctx, ipath, store, force) + }() + select { + case <-time.After(75 * time.Second): + return false, errors.New("index migration timed out after 75 seconds") + case result := <-result: + return result.Indexed, result.Error + } +} + +func doMigrateIndex(ctx context.Context, ipath idxPath, store StoreMigrationApi, force bool) migrateIndexResult { + indexed, err := migrateIndex(ctx, ipath, store, force) + return migrateIndexResult{ + Indexed: indexed, + Error: err, + } +} + func migrateIndex(ctx context.Context, ipath idxPath, store StoreMigrationApi, force bool) (bool, error) { pieceCid, err := cid.Parse(ipath.name) if err != nil {