{"record":{"id":"7c03635d573f7867","repo":"ipfs/kubo","slug":"s-w-7c0363","errorCode":null,"errorMessage":"%s, %w","messagePattern":"%s, %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"repo/fsrepo/migrations/migrations.go","lineNumber":315,"sourceCode":"\t\t\t\tlogger.Printf(\"could not download %s: %s\", name, err)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tlogger.Printf(\"Downloaded and unpacked migration: %s (%s)\", loc, ver)\n\t\t\tbins[i] = loc\n\t\t}(i, name)\n\t}\n\twg.Wait()\n\n\tvar fails []string\n\tfor i := range bins {\n\t\tif bins[i] == \"\" {\n\t\t\tfails = append(fails, needed[i])\n\t\t}\n\t}\n\tif len(fails) != 0 {\n\t\terr = fmt.Errorf(\"failed to download migrations: %s\", strings.Join(fails, \" \"))\n\t\tif ctx.Err() != nil {\n\t\t\terr = fmt.Errorf(\"%s, %w\", ctx.Err(), err)\n\t\t}\n\t\treturn nil, err\n\t}\n\n\treturn bins, nil\n}\n\n// RunHybridMigrations intelligently runs migrations using external tools for legacy versions\n// and embedded migrations for modern versions. This handles the transition from external\n// fs-repo-migrations binaries (for repo versions <16) to embedded migrations (for repo versions ≥16).\n//\n// The function automatically:\n// 1. Uses external migrations to get from current version to v16 (if needed)\n// 2. Uses embedded migrations for v16+ steps\n// 3. Handles pure external, pure embedded, or mixed migration scenarios\n//\n// Legacy external migrations (repo versions <16) only support HTTPS downloads.\n//","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/repo/fsrepo/migrations/migrations.go#L297-L333","documentation":"A wrapper error for the failed-download case: when downloads failed AND the context was cancelled/timed out, fetchMigrations prefixes the download-failure error with the context error, using %w to preserve unwrapping of the inner download error.","triggerScenarios":"The context passed to fetchMigrations (via RunMigration) is cancelled or times out while/after some migration downloads fail — e.g. user hits Ctrl-C during `ipfs daemon --migrate`, or a parent timeout expires mid-download.","commonSituations":"Daemon startup with a systemd/supervisor timeout that cancels migration context; Ctrl-C during a long download; test harness context deadlines.","solutions":["Re-run the migration with an adequate timeout and without cancelling the daemon","Use `ipfs daemon --migrate` interactively and wait for completion","Check errors.Is(err, context.DeadlineExceeded)/Canceled to confirm the cancellation, then address why it was cancelled","Increase systemd TimeoutStartSec or supervisor stop/start timeouts around the daemon"],"exampleFix":"// before\nctx, cancel := context.WithTimeout(ctx, 30*time.Second)\ndefer cancel()\nerr := migration.RunMigration(ctx, fetcher, ver, dir, false)\n// after\nctx, cancel := context.WithTimeout(ctx, 15*time.Minute) // migrations can be slow\ndefer cancel()\nerr := migration.RunMigration(ctx, fetcher, ver, dir, false)","handlingStrategy":"try-catch","validationCode":"// ensure the context has generous time before calling\ntimeout := 15 * time.Minute\nctx, cancel := context.WithTimeout(ctx, timeout)\ndefer cancel()","typeGuard":null,"tryCatchPattern":"if err != nil {\n    if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {\n        log.Println(\"migration aborted: context cancelled; re-run without interruption\")\n    }\n    return err\n}","preventionTips":["Give migrations long timeouts (they download and run many binaries)","Avoid wrapping RunMigration in short-lived request contexts","Increase systemd TimeoutStartSec for the daemon","Don't Ctrl-C mid-migration; wait for completion"],"tags":["migrations","context-cancellation","error-wrapping"],"backgroundTag":"context-canceled-during-download","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}