Skip to content

pi update --self gives up after one transient latest-version connection failure #6675

Description

@whyhkzk

What happened?

pi update --self sometimes fails with:

Error: Could not determine latest pi version: fetch failed

The self-update path makes one request to https://pi.dev/api/latest-version. A transient connection failure stops the update immediately. The message shown to the user is only fetch failed. The useful network errors remain in error.cause.

Steps to reproduce

I ran the request used by getLatestPiRelease() in fresh Node.js processes on several servers in mainland China and the US. Proxies were disabled for all tests.

  • Mainland China: 13 failures in 56 requests.
  • US: all 16 requests succeeded.
  • Failures ended after about 0.55 seconds with AggregateError: ETIMEDOUT, containing two IPv4 ETIMEDOUT errors and two IPv6 ENETUNREACH errors.
  • On four affected hosts, disabling autoSelectFamily and using IPv4-first made all 24 requests succeed.

The failures occur during Node's dual-stack connection race: IPv6 is unreachable, while both IPv4 candidates can time out within their per-address attempt windows.

In three cases where the first request failed, an immediate retry in the same Node.js process succeeded. This suggests that a single retry can often recover from this failure mode.

Expected behavior

Retry the latest-version request once when pi update --self hits a transient connection failure such as ETIMEDOUT. If it fails again, surface the underlying cause. The startup version check should remain unchanged.

I'm happy to send a fix.

Version

0.80.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions