Skip to content

fix: download p2pd on first use, using got#94

Open
tabcat wants to merge 5 commits into
libp2p:masterfrom
tabcat:fix/download-on-first-use
Open

fix: download p2pd on first use, using got#94
tabcat wants to merge 5 commits into
libp2p:masterfrom
tabcat:fix/download-on-first-use

Conversation

@tabcat

@tabcat tabcat commented Jul 8, 2026

Copy link
Copy Markdown
Member

The postinstall download is best-effort: npm v12 makes install scripts opt-in by default, and --ignore-scripts, pnpm and hardened CI already skip them, so the p2pd binary can silently go missing. Separately, the download used the global fetch, whose response body drain stalls indefinitely on some platforms (e.g. GitHub's macos-26 runners).

  • Keep the postinstall as a fast path, but download on first use as a fallback: path() runs the installer in a child process when the binary isn't present, so a skipped script heals itself. Pass path({ autoDownload: false }) to resolve only an already-installed binary.
  • Download with got instead of the global fetch. got reads the body reliably and handles retries/backoff itself (drops the now-unused p-retry, delay, browser-readablestream-to-it and it-to-buffer).
  • bin/p2pd ships as a JS stub the installer replaces, so path() treats that stub as not-installed and downloads on first call.

Same approach as ipfs/npm-kubo#83.

tabcat added 4 commits July 8, 2026 19:18
npm v12 makes install scripts opt-in, and --ignore-scripts, pnpm and hardened CI already skip them. Keep the postinstall as a best-effort fast path, but fall back to downloading from path() (running the installer in a child process) when the binary is missing.
Draining a global-fetch response body stalls indefinitely on some platforms (notably GitHub's macos-26 runners); got reads it reliably and handles retries/backoff. Drops the now-unused browser-readablestream-to-it, it-to-buffer, p-retry and delay deps.
@tabcat

tabcat commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

Note on retry handling: I dropped the custom retries/retryDelay options (and the undocumented RETRIES/RETRY_DELAY env vars) and switched to plain got(url).buffer(), so downloads now use got's built-in retry and backoff defaults. This keeps it in line with how npm-kubo does it (ipfs/npm-kubo#83).

Happy to restore the knobs if you'd prefer to keep them (got's retry.calculateDelay can reproduce the old fixed delay), but matching kubo felt cleaner.

@tabcat
tabcat marked this pull request as ready for review July 8, 2026 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants