@devries-cameron20 / composio Mirror · read-only / commits / b08b18d73
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 17:15 UTC

fix(version): improve timeout handling in NPM version check and add related tests

rajashidattapy committed Aug 4, 2026 at 11:59 UTC b08b18d73b1e76cb3a5c4bd1d4c91316d444ffc9
2 files changed +30 -5
ts/packages/core/src/utils/version.ts
+16 -5
@@ -53,11 +53,22 @@ export async function checkForLatestVersionFromNPM(currentVersion: string) {
53 // keeps its socket referenced on the event loop, so without a signal a slow or
54 // black-holed registry (corporate proxy, egress firewall that drops rather than
55 // rejects, npm incident) keeps short-lived scripts alive until undici's own
56 - // timeouts fire. The catch below already swallows the resulting TimeoutError.
57 - const response = await fetch(`https://registry.npmjs.org/${packageName}/latest`, {
58 - signal: AbortSignal.timeout(VERSION_CHECK_TIMEOUT_MS),
59 - });
60 - const data = await response.json();
56 + // timeouts fire. The catch below already swallows the resulting abort.
57 + //
58 + // A hand-rolled timer rather than AbortSignal.timeout so it can be cleared the
59 + // moment the response lands: an uncleared timer is itself pending work, which on
60 + // workerd pins the request context open for the full timeout on every success.
61 + const controller = new AbortController();
62 + const timer = setTimeout(() => controller.abort(), VERSION_CHECK_TIMEOUT_MS);
63 + let data;
64 + try {
65 + const response = await fetch(`https://registry.npmjs.org/${packageName}/latest`, {
66 + signal: controller.signal,
67 + });
68 + data = await response.json();
69 + } finally {
70 + clearTimeout(timer);
71 + }
72 const latestVersion = data.version;
73
74 if (semver.gt(latestVersion, currentVersionFromPackageJson) && !IS_DEVELOPMENT_OR_CI) {
ts/packages/core/test/utils/version.test.ts
+14
@@ -17,6 +17,20 @@ describe('checkForLatestVersionFromNPM', () => {
17 expect(init?.signal).toBeInstanceOf(AbortSignal);
18 });
19
20 + it('leaves no pending timer once the registry responds', async () => {
21 + vi.useFakeTimers();
22 + vi.stubGlobal(
23 + 'fetch',
24 + vi.fn(async () => new Response(JSON.stringify({ version: '0.0.1' })))
25 + );
26 +
27 + await checkForLatestVersionFromNPM('1.0.0');
28 +
29 + // An uncleared timeout keeps a workerd request context alive for its full duration.
30 + expect(vi.getTimerCount()).toBe(0);
31 + vi.useRealTimers();
32 + });
33 +
34 it('gives up instead of hanging when the registry never responds', async () => {
35 // A registry that accepts the request and never answers. Without a timeout this
36 // promise never settles, which is exactly what keeps a real process alive.