Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
fix(telemetry): clear timeout on serialization errors
jkomynocf4232804015
diff --git a/ts/packages/core/src/services/telemetry/TelemetryService.ts b/ts/packages/core/src/services/telemetry/TelemetryService.tsindex 6a758003a..1121c66a7 100644--- a/ts/packages/core/src/services/telemetry/TelemetryService.ts+++ b/ts/packages/core/src/services/telemetry/TelemetryService.ts@@ -14,17 +14,21 @@ export class TelemetryService {* workerd pins the request context open for the full timeout on every successful* send. Mirrors the bound applied to the npm version check.*/- private static postWithTimeout(url: string, payload: unknown) {+ private static async postWithTimeout(url: string, payload: unknown) {const controller = new AbortController();const timer = setTimeout(() => controller.abort(), TELEMETRY_TIMEOUT_MS);- return fetch(url, {- method: 'POST',- headers: {- 'Content-Type': 'application/json',- },- body: JSON.stringify(payload),- signal: controller.signal,- }).finally(() => clearTimeout(timer));+ try {+ return await fetch(url, {+ method: 'POST',+ headers: {+ 'Content-Type': 'application/json',+ },+ body: JSON.stringify(payload),+ signal: controller.signal,+ });+ } finally {+ clearTimeout(timer);+ }}/**diff --git a/ts/packages/core/test/telemetry/TelemetryService.test.ts b/ts/packages/core/test/telemetry/TelemetryService.test.tsindex b089ae638..eb4bf6578 100644--- a/ts/packages/core/test/telemetry/TelemetryService.test.ts+++ b/ts/packages/core/test/telemetry/TelemetryService.test.ts@@ -460,6 +460,18 @@ describe('TelemetryService network bounding', () => {expect(vi.getTimerCount()).toBe(0);});+ it('clears the timer when serializing the payload fails', async () => {+ vi.useFakeTimers();+ const fetchMock = vi.fn<typeof fetch>();+ vi.stubGlobal('fetch', fetchMock);++ const payload = createPayload({ props: { value: BigInt(1) } });++ await expect(TelemetryService.sendMetric([payload])).resolves.toBeUndefined();+ expect(fetchMock).not.toHaveBeenCalled();+ expect(vi.getTimerCount()).toBe(0);+ });+it('swallows a sendMetric timeout when the endpoint never responds', async () => {vi.useFakeTimers();const fetchMock = vi.fn<typeof fetch>(