From 1c7d9255ae5333ff717b9f32ef7adf1690cbb163 Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Fri, 21 Oct 2022 19:07:39 +0300 Subject: [PATCH] Stop waiting for the analytics response Change-type: patch See: https://balena.zulipchat.com/#narrow/stream/345884-aspect.2Fanalytics/topic/Balena.20CLI.20analytics-performance Signed-off-by: Thodoris Greasidis --- lib/events.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/events.ts b/lib/events.ts index ff4703ed..fd0f74f6 100644 --- a/lib/events.ts +++ b/lib/events.ts @@ -73,6 +73,8 @@ export async function trackCommand(commandSignature: string) { } } +const TIMEOUT = 4000; + /** * Make the event tracking HTTPS request to balenaCloud's '/mixpanel' endpoint. */ @@ -100,14 +102,23 @@ async function sendEvent(balenaUrl: string, event: string, username?: string) { await got.post(url, { json: trackData, retry: 0, - timeout: 4000, + timeout: { + // Starts when the request is initiated. + request: TIMEOUT, + // Starts when request has been flushed. + // Exits the request as soon as it's sent. + response: 0, + }, }); } catch (e) { if (process.env.DEBUG) { console.error(`[debug] Event tracking error: ${e.message || e}`); } - if (e instanceof got.TimeoutError) { + if ( + e instanceof got.TimeoutError && + TIMEOUT < (e.timings.phases.total ?? 0) + ) { console.error(stripIndent` Timeout submitting analytics event to balenaCloud/openBalena. If you are using the balena CLI in an air-gapped environment with a filtered