diff --git a/package-lock.json b/package-lock.json index b0454c3189..d007b18c21 100644 --- a/package-lock.json +++ b/package-lock.json @@ -47,6 +47,7 @@ "scheduler": "^0.22.0", "semver": "^7.3.7", "systeminformation": "^5.11.16", + "undici": "^5.22.1", "use-context-selector": "^1.4.0", "use-debounce": "^8.0.1", "use-http": "^1.0.26", @@ -7451,6 +7452,17 @@ "integrity": "sha512-4/rOEg86jivtPTeOUUT61jJO1Ya1TrR/OkqCSZDyq84WJh3LuuiphBYJN+fm5xufIk4XAFcEwte/8WzC8If/1g==", "dev": true }, + "node_modules/busboy": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", + "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==", + "dependencies": { + "streamsearch": "^1.1.0" + }, + "engines": { + "node": ">=10.16.0" + } + }, "node_modules/bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -21823,6 +21835,14 @@ "node": ">= 0.10.0" } }, + "node_modules/streamsearch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", + "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==", + "engines": { + "node": ">=10.0.0" + } + }, "node_modules/strict-uri-encode": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz", @@ -23221,6 +23241,17 @@ "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==", "dev": true }, + "node_modules/undici": { + "version": "5.22.1", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.22.1.tgz", + "integrity": "sha512-Ji2IJhFXZY0x/0tVBXeQwgPlLWw13GVzpsWPQ3rV50IFMMof2I55PZZxtm4P6iNq+L5znYN9nSTAq0ZyE6lSJw==", + "dependencies": { + "busboy": "^1.6.0" + }, + "engines": { + "node": ">=14.0" + } + }, "node_modules/unified": { "version": "10.1.2", "resolved": "https://registry.npmjs.org/unified/-/unified-10.1.2.tgz", @@ -30190,6 +30221,14 @@ "integrity": "sha512-4/rOEg86jivtPTeOUUT61jJO1Ya1TrR/OkqCSZDyq84WJh3LuuiphBYJN+fm5xufIk4XAFcEwte/8WzC8If/1g==", "dev": true }, + "busboy": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", + "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==", + "requires": { + "streamsearch": "^1.1.0" + } + }, "bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -40862,6 +40901,11 @@ "dev": true, "optional": true }, + "streamsearch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", + "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==" + }, "strict-uri-encode": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz", @@ -41901,6 +41945,14 @@ "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==", "dev": true }, + "undici": { + "version": "5.22.1", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.22.1.tgz", + "integrity": "sha512-Ji2IJhFXZY0x/0tVBXeQwgPlLWw13GVzpsWPQ3rV50IFMMof2I55PZZxtm4P6iNq+L5znYN9nSTAq0ZyE6lSJw==", + "requires": { + "busboy": "^1.6.0" + } + }, "unified": { "version": "10.1.2", "resolved": "https://registry.npmjs.org/unified/-/unified-10.1.2.tgz", diff --git a/package.json b/package.json index 369be00943..6239d8774f 100644 --- a/package.json +++ b/package.json @@ -140,6 +140,7 @@ "scheduler": "^0.22.0", "semver": "^7.3.7", "systeminformation": "^5.11.16", + "undici": "^5.22.1", "use-context-selector": "^1.4.0", "use-debounce": "^8.0.1", "use-http": "^1.0.26", diff --git a/src/common/Backend.ts b/src/common/Backend.ts index fee806215d..6e98b0c65a 100644 --- a/src/common/Backend.ts +++ b/src/common/Backend.ts @@ -1,3 +1,4 @@ +import { fetch as undiciFetch, Agent as undiciAgent } from 'undici'; import { BackendJsonNode, Category, @@ -10,6 +11,7 @@ import { SchemaId, } from './common-types'; import { Package } from './dependencies'; +import { isRenderer } from './env' export interface BackendSuccessResponse { type: 'success'; @@ -103,7 +105,12 @@ export class Backend { } private async fetchJson(path: string, method: 'POST' | 'GET', json?: unknown): Promise { - const options: RequestInit = { method, cache: 'no-cache' }; + const options: RequestInit = isRenderer ? + { method, cache: 'no-cache' } : + { method, cache: 'no-cache', + dispatcher: new undiciAgent({ + bodyTimeout: 0, + headersTimeout: 0}) }; const { signal } = this.abortController; if (json !== undefined) { options.body = JSON.stringify(json); @@ -112,8 +119,7 @@ export class Backend { }; options.signal = signal; } - - const resp = await fetch(`http://127.0.0.1:${this.port}${path}`, options); + const resp = await (isRenderer ? fetch : undiciFetch)(`http://127.0.0.1:${this.port}${path}`, options); return (await resp.json()) as T; }