Skip to content

Commit

Permalink
Disable bodyTimeout and headersTimeout when CLI fetching from backend
Browse files Browse the repository at this point in the history
Fixes bug where CLI would crash if the chain took more than 5 minutes to
process.
  • Loading branch information
Splendide-Imaginarius committed Jun 13, 2023
1 parent 3c39d21 commit f9b67d4
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
52 changes: 52 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 9 additions & 3 deletions src/common/Backend.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { fetch as undiciFetch, Agent as undiciAgent } from 'undici';
import {
BackendJsonNode,
Category,
Expand All @@ -10,6 +11,7 @@ import {
SchemaId,
} from './common-types';
import { Package } from './dependencies';
import { isRenderer } from './env'

export interface BackendSuccessResponse {
type: 'success';
Expand Down Expand Up @@ -103,7 +105,12 @@ export class Backend {
}

private async fetchJson<T>(path: string, method: 'POST' | 'GET', json?: unknown): Promise<T> {
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);
Expand All @@ -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;
}

Expand Down

0 comments on commit f9b67d4

Please sign in to comment.