Merge pull request #2553 from balena-io/stop-waiting-for-the-analytics-response

Stop waiting for the analytics response
This commit is contained in:
bulldozer-balena[bot] 2022-10-21 17:09:08 +00:00 committed by GitHub
commit 6f5ada9692
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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