Use socket timeout on updater downloads

This commit is contained in:
Fedor Indutny 2021-07-15 17:57:34 -07:00 committed by GitHub
parent 234d324751
commit 8a413beaf2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 2 deletions

View file

@ -39,6 +39,9 @@ const rimrafPromise = pify(rimraf);
const { platform } = process;
export const ACK_RENDER_TIMEOUT = 10000;
export const GOT_CONNECT_TIMEOUT = 2 * 60 * 1000;
export const GOT_LOOKUP_TIMEOUT = 2 * 60 * 1000;
export const GOT_SOCKET_TIMEOUT = 2 * 60 * 1000;
export type UpdaterInterface = {
force(): Promise<void>;
@ -337,6 +340,13 @@ function getGotOptions(): GotOptions<null> {
'User-Agent': getUserAgent(packageJson.version),
},
useElectronNet: false,
timeout: {
connect: GOT_CONNECT_TIMEOUT,
lookup: GOT_LOOKUP_TIMEOUT,
// This timeout is reset whenever we get new data on the socket
socket: GOT_SOCKET_TIMEOUT,
},
};
}

View file

@ -82,10 +82,20 @@ async function checkDownloadAndInstall(
const { fileName: newFileName, version: newVersion } = result;
if (fileName !== newFileName || !version || gt(newVersion, version)) {
const oldFileName = fileName;
const oldVersion = version;
deleteCache(updateFilePath, logger);
fileName = newFileName;
version = newVersion;
updateFilePath = await downloadUpdate(fileName, logger);
try {
updateFilePath = await downloadUpdate(fileName, logger);
} catch (error) {
// Restore state in case of download error
fileName = oldFileName;
version = oldVersion;
throw error;
}
}
if (!updateFilePath) {

View file

@ -83,10 +83,21 @@ async function checkDownloadAndInstall(
const { fileName: newFileName, version: newVersion } = result;
if (fileName !== newFileName || !version || gt(newVersion, version)) {
const oldFileName = fileName;
const oldVersion = version;
deleteCache(updateFilePath, logger);
fileName = newFileName;
version = newVersion;
updateFilePath = await downloadUpdate(fileName, logger);
try {
updateFilePath = await downloadUpdate(fileName, logger);
} catch (error) {
// Restore state in case of download error
fileName = oldFileName;
version = oldVersion;
throw error;
}
}
const publicKey = hexToBinary(getFromConfig('updatesPublicKey'));