Skip to content

fix(plugin-typescript): add a timeout to the Algolia auto-types lookup - #7206

Open
sebdanielsson wants to merge 2 commits into
yarnpkg:masterfrom
sebdanielsson:claude/berry-7111-fix-8doaul
Open

fix(plugin-typescript): add a timeout to the Algolia auto-types lookup#7206
sebdanielsson wants to merge 2 commits into
yarnpkg:masterfrom
sebdanielsson:claude/berry-7111-fix-8doaul

Conversation

@sebdanielsson

@sebdanielsson sebdanielsson commented Jun 27, 2026

Copy link
Copy Markdown

What's the problem this PR addresses?

Closes #7111

yarn add queries Algolia's npm-search index to detect whether the added package needs a matching @types package. In our corporate network, all egress traffic traverses our HTTP proxy. If this is set globally using HTTPS_PROXY, HTTP_PROXY, and NO_PROXY, but not explicitly with Yarn's HTTP proxy config, this query will not go through the proxy but will instead try to make a direct connection. In our case, this means the firewall silently drops the connection.

httpTimeout is not what's bounding a single attempt. I dropped it from 15s to 10s and got an identical ~135s per attempt. The wait is the Linux kernel's TCP SYN-retry exhaustion (default tcp_syn_retries=6, ~127–135s in my tests). Because the TCP socket never establishes, got's timeout.socket (which is socket-inactivity-after-connect) never starts. Got then retries httpRetry times, which multiplies the dead time.

My tests:

Settings Total Per attempt Attempts
httpTimeout=10s httpRetry=0 135s ~135s 1
httpTimeout=10s httpRetry=1 269s ~135s 2
httpTimeout=15s httpRetry=1 270s ~135s 2
Defaults (httpTimeout=1m httpRetry=3) 546s (~9m) ~135s 4

How did you fix it?

This caps the lookup at 10s and, on timeout or network failure, warns the user (pointing at the tsEnableAutoTypes: false / YARN_TS_ENABLE_AUTO_TYPES="false" escape hatch) before letting the install proceed without the @types package. It also hardens the Algolia requester so a connection error without a response no longer throws an unrelated TypeError.

Future fixes

My last comment in the linked issue proposes additional fixes to make this more stable, but I wanted to keep this PR small and easy to review. A future enhancement would be to have the Algolia lookup respect the global HTTP environments, just like the installation does today.

Checklist

  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

@sebdanielsson

Copy link
Copy Markdown
Author

CI failures seem to be pre-existing.

@sebdanielsson
sebdanielsson force-pushed the claude/berry-7111-fix-8doaul branch from 2ac69a6 to 0749d72 Compare July 1, 2026 17:04
Copilot AI review requested due to automatic review settings July 1, 2026 17:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses yarn add hanging in network-restricted environments by bounding the optional Algolia lookup used by @yarnpkg/plugin-typescript to decide whether to add a matching @types/* dependency, and by improving resilience to connection errors.

Changes:

  • Add a 10s timeout wrapper around the Algolia npm-search lookup and warn (then continue) on timeout/network failure.
  • Harden the Algolia requester error path to avoid throwing when error.response is missing.
  • Add a versioning file to release @yarnpkg/plugin-typescript as a patch.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/plugin-typescript/sources/typescriptUtils.ts Adds a timeout + warning path for the Algolia auto-types lookup and guards requester error handling.
.yarn/versions/7111fix0.yml Declares a patch release for @yarnpkg/plugin-typescript.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/plugin-typescript/sources/typescriptUtils.ts Outdated
Comment thread packages/plugin-typescript/sources/typescriptUtils.ts
Comment thread packages/plugin-typescript/sources/typescriptUtils.ts
@sebdanielsson sebdanielsson reopened this Jul 18, 2026
@sebdanielsson
sebdanielsson force-pushed the claude/berry-7111-fix-8doaul branch from 0749d72 to a9c7b69 Compare July 18, 2026 16:04
@sebdanielsson
sebdanielsson force-pushed the claude/berry-7111-fix-8doaul branch from a9c7b69 to 6ecd751 Compare July 29, 2026 13:44
@sebdanielsson

Copy link
Copy Markdown
Author

@clemyan What do you think about this change?

Bound the optional Algolia auto-types lookup to 10 seconds and cancel the underlying Yarn HTTP request when the deadline expires, including active proxy tunnels. This releases the network concurrency slot and prevents Algolia from retrying fallback hosts after the command has already continued.

Warn clearly on timeout or network failure, continue without the matching @types package, and harden transport errors that have no response. Add deterministic cancellation and warning coverage.

Closes yarnpkg#7111

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

Claude-Session: https://claude.ai/code/session_01NS1JKnVAz9uPwdyUhfub2g

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@sebdanielsson
sebdanielsson force-pushed the claude/berry-7111-fix-8doaul branch from 6ecd751 to 99d459a Compare July 30, 2026 10:13

@clemyan clemyan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavioral side of the fix is good. Left a few comments regarding the tests and complexity.

However, I am still unsure whether this is the correct approach. On one hand, it is a small, cotained change that is unlikely to adversely affect other things. On the other, being stuck on socket connection can happen to any HTTP requests, so I wonder if we should just apply httpTimeout end-to-end for all HTTP requests using the same method.

@arcanis wdyt?

Comment thread .yarn/versions/7111fix0.yml Outdated
Comment thread packages/plugin-typescript/sources/typescriptUtils.ts Outdated
Comment thread packages/yarnpkg-core/tests/httpUtils.test.ts Outdated
Comment thread packages/yarnpkg-core/tests/httpUtils.test.ts Outdated
Comment thread packages/yarnpkg-core/tests/httpUtils.test.ts Outdated
Comment thread packages/yarnpkg-core/tests/httpUtils.test.ts Outdated
Comment thread packages/yarnpkg-core/tests/httpUtils.test.ts Outdated
The `afterWorkspaceDependencyAddition` and `afterWorkspaceDependencyReplacement`
hooks were triggered outside of any report, so warnings they emitted (such as the
new plugin-typescript one) were printed as raw Node.js process warnings instead
of regular Yarn messages.

Also addresses the review feedback on yarnpkg#7206:

- drops the `Promise.race` in `hasDefinitelyTyped` in favour of checking
  `signal.aborted` in the `catch` clause
- rewrites the httpUtils cancellation tests around `events.once`,
  `server.closeAllConnections()`, and `setTimeout` from `timers/promises`
- adds an acceptance test covering an unreachable Algolia index
- releases `@yarnpkg/cli` and `@yarnpkg/plugin-essentials`

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0158RapNp7NHWhFqHp3gKNxm
arcanis added a commit to yarnpkg/zpm that referenced this pull request Aug 15, 2026
## What's the problem this PR addresses?

A review of recent Berry PRs identified several fixes and regression
tests that also apply to zpm. This PR backports them in one batch.

## How did I fix it?

**Bug fixes (the ported regression tests reproduced each of these before
the fix):**

- yarnpkg/berry#7205 — `*` now resolves to prereleases when a package
has no stable version. The fallback only applies to a literal `*` range
(not the internal `>=0.0.0-0` any-range), and `--check-resolutions`
accepts the resulting prerelease pins.
- yarnpkg/berry#7216 — the nm linker now prefers direct dependency
binaries over transitively-hoisted aliases when two packages expose the
same bin name, instead of resolving collisions by ident order.
- yarnpkg/berry#7209 — commands that need an npm OTP now fail with a
`--otp` hint when not attached to an interactive terminal, instead of
blocking forever on a prompt.
- yarnpkg/berry#7255 — `yarn npm audit --recursive --environment
production` no longer reports advisories only reachable through a nested
workspace's devDependencies.
- yarnpkg/berry#7253 — `yarn info --virtuals` now reports base
descriptors alongside virtual locators (zpm had the mirror image of
Berry's bug: correct locators, virtualized descriptors).
- yarnpkg/berry#7206 — a failed Algolia auto-types lookup no longer
aborts `yarn add`; it degrades to a warning (with the `enableAutoTypes`
escape hatch) and the lookup is bounded by a 10s per-request timeout.

**Feature:**

- yarnpkg/berry#7243 — `supportedArchitectures` additionally accepts a
list of explicit os/cpu/libc combinations (matched per-entry, no
cross-product), with the same config syntax as Berry.

**Tests only (zpm's behavior was already correct):**

- yarnpkg/berry#7250 / yarnpkg/berry#7257 — gate bypass for packages
without release-time metadata, plus the `no-time-deps` fixture and
registry-mock support.
- yarnpkg/berry#7214 — scoped-gate inheritance tests, adapted to zpm's
`packageRules`/`sourceRules` model (zpm's Option-based overrides make
Berry's default-shadowing bug structurally impossible).

**Artifact sync:**

- Re-ran `scripts/import-artifacts.mjs` against Berry master, picking up
yarnpkg/berry#7232 and the extensions hunk of yarnpkg/berry#7228 (8 new
package extensions: 5 Volar `typescript` peers,
`vite-plugin-vue-devtools`, 2 Parcel entries) along with forward-only
PnP hook/patch updates.

## Checklist

- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).
- [x] I have checked that all the impacted tests pass: the touched
acceptance suites (npmMinimalAgeGate, prunedNativeDeps, protocols/npm,
npm/audit, info, publish, node-modules, packageExtensions,
checkResolutions, add) pass 215/218 (3 skipped), plus `cargo test` for
zpm-config (7) and zpm-semver (108). The only remaining local failures
reproduce identically on a pristine `main` build (venv/Python
environment, one live-Algolia-data test, `path_iterators` and two
lazyInstalls focus-coverage tests).

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Touches core install resolution, architecture filtering, and audit
traversal; behavior changes are intentional but affect many installs and
multi-arch fetches.
> 
> **Overview**
> Backports a batch of Berry fixes and tests into zpm, covering install
resolution, CLI behavior, configuration, and artifact sync.
> 
> **Resolution & install:** Literal `*` ranges can resolve to
prereleases when no stable versions exist, with matching
`--check-resolutions` acceptance. Algolia auto-`@types` lookup is capped
at 10s, warns instead of failing `yarn add`, and respects
`enableAutoTypes`. HTTP requests gain a per-request `.timeout()` bounded
by `httpTimeout`.
> 
> **Commands & linkers:** `npm publish` errors with a `--otp` hint when
not on an interactive TTY. Recursive production `npm audit` skips nested
workspaces’ devDependencies. `yarn info --virtuals` shows physical
descriptors with virtual locators. Node-modules bin symlinks prefer
direct dependencies over hoisted aliases.
> 
> **`supportedArchitectures`:** Schema becomes a `oneOrMany` list of
entries with `ArchitectureFilter` fields (`null` = any). Legacy
single-object YAML still works; project config replaces (not merges)
user entries. Matching uses `SystemSet` / `supported_systems()` with
per-entry validation instead of a flat cross-product of all systems.
> 
> **Artifacts:** `builtin-extensions.json` gains Volar, Vite devtools,
and Parcel peer entries; package manager pin updated.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
4aaf6a1. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
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.

[Bug?]: yarn add unexpectedly hangs in network restricted environments

4 participants