fix(plugin-typescript): add a timeout to the Algolia auto-types lookup - #7206
fix(plugin-typescript): add a timeout to the Algolia auto-types lookup#7206sebdanielsson wants to merge 2 commits into
Conversation
|
CI failures seem to be pre-existing. |
2ac69a6 to
0749d72
Compare
There was a problem hiding this comment.
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-searchlookup and warn (then continue) on timeout/network failure. - Harden the Algolia requester error path to avoid throwing when
error.responseis missing. - Add a versioning file to release
@yarnpkg/plugin-typescriptas 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.
0749d72 to
a9c7b69
Compare
a9c7b69 to
6ecd751
Compare
|
@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>
6ecd751 to
99d459a
Compare
clemyan
left a comment
There was a problem hiding this comment.
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?
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
What's the problem this PR addresses?
Closes #7111
yarn addqueries Algolia'snpm-searchindex to detect whether the added package needs a matching@typespackage. In our corporate network, all egress traffic traverses our HTTP proxy. If this is set globally usingHTTPS_PROXY,HTTP_PROXY, andNO_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.httpTimeoutis 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:
httpTimeout=10s httpRetry=0httpTimeout=10s httpRetry=1httpTimeout=15s httpRetry=1httpTimeout=1m httpRetry=3)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@typespackage. It also hardens the Algolia requester so a connection error without aresponseno longer throws an unrelatedTypeError.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