@@ -245,10 +245,17 @@ func migrateIndices(ctx context.Context, logger *zap.SugaredLogger, bar *progres
245
245
246
246
start := time .Now ()
247
247
248
- indexed , err := migrateIndex (ctx , ipath , store , force )
248
+ timeoutCtx , timeoutCancel := context .WithTimeout (ctx , 60 * time .Second )
249
+ defer timeoutCancel ()
250
+
251
+ indexed , err := migrateIndexWithTimeout (timeoutCtx , ipath , store , force )
249
252
bar .Add (1 ) //nolint:errcheck
250
253
if err != nil {
251
- logger .Errorw ("migrate index failed" , "piece cid" , ipath .name , "err" , err )
254
+ took := time .Since (start )
255
+ indexTime += took
256
+
257
+ logger .Errorw ("migrate index failed" , "piece cid" , ipath .name , "took" , took .String (), "err" , err )
258
+
252
259
errCount ++
253
260
continue
254
261
}
@@ -268,6 +275,32 @@ func migrateIndices(ctx context.Context, logger *zap.SugaredLogger, bar *progres
268
275
return errCount , nil
269
276
}
270
277
278
+ type migrateIndexResult struct {
279
+ Indexed bool
280
+ Error error
281
+ }
282
+
283
+ func migrateIndexWithTimeout (ctx context.Context , ipath idxPath , store StoreMigrationApi , force bool ) (bool , error ) {
284
+ result := make (chan migrateIndexResult , 1 )
285
+ go func () {
286
+ result <- doMigrateIndex (ctx , ipath , store , force )
287
+ }()
288
+ select {
289
+ case <- time .After (75 * time .Second ):
290
+ return false , errors .New ("index migration timed out after 75 seconds" )
291
+ case result := <- result :
292
+ return result .Indexed , result .Error
293
+ }
294
+ }
295
+
296
+ func doMigrateIndex (ctx context.Context , ipath idxPath , store StoreMigrationApi , force bool ) migrateIndexResult {
297
+ indexed , err := migrateIndex (ctx , ipath , store , force )
298
+ return migrateIndexResult {
299
+ Indexed : indexed ,
300
+ Error : err ,
301
+ }
302
+ }
303
+
271
304
func migrateIndex (ctx context.Context , ipath idxPath , store StoreMigrationApi , force bool ) (bool , error ) {
272
305
pieceCid , err := cid .Parse (ipath .name )
273
306
if err != nil {
0 commit comments