-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: retry renaming update file when EBUSY error occurs due to file l…
…ock (#8437)
- Loading branch information
1 parent
d5d9f3f
commit be625e0
Showing
5 changed files
with
36 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"builder-util": patch | ||
"builder-util-runtime": patch | ||
"electron-updater": patch | ||
--- | ||
|
||
fix: retry renaming update file when EBUSY error occurs due to file lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { CancellationToken } from "./CancellationToken" | ||
|
||
export async function retry<T>(task: () => Promise<T>, retryCount: number, interval: number, backoff = 0, attempt = 0, shouldRetry?: (e: any) => boolean): Promise<T> { | ||
const cancellationToken = new CancellationToken() | ||
try { | ||
return await task() | ||
} catch (error: any) { | ||
if ((shouldRetry?.(error) ?? true) && retryCount > 0 && !cancellationToken.cancelled) { | ||
await new Promise(resolve => setTimeout(resolve, interval + backoff * attempt)) | ||
return await retry(task, retryCount - 1, interval, backoff, attempt + 1, shouldRetry) | ||
} else { | ||
throw error | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters