Use socket timeout on updater downloads
This commit is contained in:
parent
234d324751
commit
8a413beaf2
3 changed files with 33 additions and 2 deletions
|
@ -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,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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'));
|
||||
|
|
Loading…
Reference in a new issue