From 8b1c58fafec026544d66ee4b9578b4bd0f30b14b Mon Sep 17 00:00:00 2001 From: Max Leiter Date: Wed, 14 Feb 2024 23:38:40 -0800 Subject: [PATCH] server/track: always consume the response body for a track request (#131) * server/track: always consume the response body for a track requeest Some cloud providers track fetch concurrency and rely on reading the body to consider a fetch completed. * Bump package version --- packages/web/package.json | 2 +- packages/web/src/server/index.ts | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/web/package.json b/packages/web/package.json index e20ba1f..a0c7fec 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -1,6 +1,6 @@ { "name": "@vercel/analytics", - "version": "1.1.3", + "version": "1.1.4", "description": "Gain real-time traffic insights with Vercel Web Analytics", "keywords": [ "analytics", diff --git a/packages/web/src/server/index.ts b/packages/web/src/server/index.ts index 72a3303..dd645b1 100644 --- a/packages/web/src/server/index.ts +++ b/packages/web/src/server/index.ts @@ -134,13 +134,17 @@ export async function track( }, body: JSON.stringify(body), method: 'POST', - }).catch((err: unknown) => { - if (err instanceof Error && 'response' in err) { - console.error(err.response); - } else { - console.error(err); - } - }); + }) + // We want to always consume to body; some cloud providers track fetch concurrency + // and may not release the connection until the body is consumed. + .then((response) => response.text()) + .catch((err: unknown) => { + if (err instanceof Error && 'response' in err) { + console.error(err.response); + } else { + console.error(err); + } + }); if (requestContext?.waitUntil) { requestContext.waitUntil(promise);