From 39b14fc4284db55b4db81a5f087a173bfda325c1 Mon Sep 17 00:00:00 2001 From: Andrey Goncharov Date: Wed, 1 Mar 2023 05:26:00 -0800 Subject: [PATCH] Track socket usage during file download Summary: Should help to investigate further issues like https://fb.workplace.com/groups/flippersupport/permalink/1577911229356196/ Reviewed By: passy Differential Revision: D43692927 fbshipit-source-id: 723b051f748946c89ece85fb6c11c40705196fe4 --- .../src/commands/DownloadFile.tsx | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/desktop/flipper-server-core/src/commands/DownloadFile.tsx b/desktop/flipper-server-core/src/commands/DownloadFile.tsx index e6766a27b..c231f4ea4 100644 --- a/desktop/flipper-server-core/src/commands/DownloadFile.tsx +++ b/desktop/flipper-server-core/src/commands/DownloadFile.tsx @@ -11,6 +11,8 @@ import {FlipperServerCommands, FlipperServerEvents, uuid} from 'flipper-common'; import {pathExists} from 'fs-extra'; import {promises, createWriteStream, ReadStream} from 'fs'; import axios from 'axios'; +import http from 'http'; +import https from 'https'; const {unlink} = promises; @@ -43,6 +45,21 @@ export const commandDownloadFileStartFactory = await unlink(dest); } + console.debug('commandDownloadFileStartFactory -> start', { + http: { + usedSockets: Object.keys(http.globalAgent.sockets).length, + freeSocket: Object.keys(http.globalAgent.freeSockets).length, + maxSockets: http.globalAgent.maxSockets, + maxTotalSockets: http.globalAgent.maxTotalSockets, + }, + https: { + usedSockets: Object.keys(https.globalAgent.sockets).length, + freeSocket: Object.keys(https.globalAgent.freeSockets).length, + maxSockets: https.globalAgent.maxSockets, + maxTotalSockets: https.globalAgent.maxTotalSockets, + }, + }); + const downloadId = uuid(); const response = await axios.request({ @@ -84,6 +101,16 @@ export const commandDownloadFileStartFactory = totalSize, status: 'success', }); + console.debug('commandDownloadFileStartFactory -> finish', { + http: { + usedSockets: Object.keys(http.globalAgent.sockets).length, + freeSocket: Object.keys(http.globalAgent.freeSockets).length, + }, + https: { + usedSockets: Object.keys(https.globalAgent.sockets).length, + freeSocket: Object.keys(https.globalAgent.freeSockets).length, + }, + }); }); writeStream.on('error', (e: Error) => { @@ -96,6 +123,16 @@ export const commandDownloadFileStartFactory = message: e.message, stack: e.stack, }); + console.debug('commandDownloadFileStartFactory -> error', { + http: { + usedSockets: Object.keys(http.globalAgent.sockets).length, + freeSocket: Object.keys(http.globalAgent.freeSockets).length, + }, + https: { + usedSockets: Object.keys(https.globalAgent.sockets).length, + freeSocket: Object.keys(https.globalAgent.freeSockets).length, + }, + }); }); return {