-
-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable bodyTimeout and headersTimeout when fetching from backend #1853
Disable bodyTimeout and headersTimeout when fetching from backend #1853
Conversation
@Splendide-Imaginarius Please explain the bug you're trying to fix a bit more. CLI and GUI use the same code for talking to the backend. The GUI obviously doesn't have this timeout problem, so why should the CLI have it? I also want to point out that the native |
Default Why does this only affect CLI? I'm honestly not sure. I spent several hours trying to trace why this behavior is CLI-specific and didn't turn up much. My working hypothesis is that the fetch of chaiNNer/src/main/cli/create.ts Line 18 in 6112174
Lines 303 to 307 in 6112174
/run fetch to time out after 5 minutes, since a chain can easily take longer than that, so I believe the correct fix is to disable the timeout rather than mess with exception handling to induce the same masking behavior in the CLI that the GUI seems to have. I suppose maybe some other endpoints might have different optimal timeouts -- maybe it would be good to tweak the timeout per endpoint if needed.
|
(If you happen to have a better understanding of why this behavior is CLI-only, maybe you can suggest a better fix than I came up with.) |
I see that the Linter is throwing a warning on CI; I'll fix that after we've figured out whether this patch is following the right approach. |
Maybe this issue does affect the GUI? I don't think I've tried a > 5 minute request since we switched to fetch |
I guess the first question here is, can you guys reproduce the |
I'm pretty sure that when I tried to do a >5 minute chain in the GUI, I didn't see any user-facing errors, but I'm not sure what exactly would be expected to happen if that |
On the very off chance that the node types have something to do with triggering the bug, I ran into the error in CLI while running a spritesheet iterator; the individual iterations were only a few seconds long, but the total time spent in the spritesheet iterator was on the order of 6-7 minutes, so just long enough to trigger the bug. |
Why does
I very much agree. I also want to point out this: Since a timeout behavior is not specified in the standard, the timeout error
This might be the case. We ignore are certain kind of exception. If Chromium implements its 300s timeout as an internal abort controller, it would make sense that the UI doesn't show us an error. chaiNNer/src/renderer/contexts/ExecutionContext.tsx Lines 299 to 306 in 6112174
So I tested this. I added This is weird because nodejs/undici#1373 mentions that Chrome has a timeout of 300s. So either Electron is setting a different timeout or something weird is going on. Note: The I also tried the same chain using CLI. I was able to reproduce the error:
So how do we fix this? I was able to verify that your PR correctly fixes the issue for CLI, but it causes issues in the GUI: So I guess one way around that would be to detect whether we are currently inside node or a browser. This would fix CLI, but it would also leave the fate (correctness) of backend requests in the GUI up to the whims of Electron, chromium, and v8. |
Good analysis @RunDevelopment , thanks for that. Yeah, seems like a mess.
I mean, I don't exactly like this solution, but I definitely can't think of a better one. Might be the least bad option. |
What's the preferred way to check whether we're running in Node vs Electron? I assume there are lots of ways to do this that will usually work, but if there's already a pattern you use in chaiNNer, I guess I should probably copy that for this PR. |
I don't think we have a way of checking that per se, we just have different entry points for CLI vs GUI |
We have |
ee8255d
to
f9b67d4
Compare
Good pointer, thanks @RunDevelopment. PR updated to only change behavior in CLI mode. |
Please run ESLint to fix the formatting: |
f9b67d4
to
3bdf9c4
Compare
For some reason |
The TypeScript linter errors may take me a few days to fix. |
What your version of ESLint? This project has ESLint in its dev deps, so we just use our version of ESLint. You did run
Here's what is happening: Native
In line 108 Here's how I would fix it: @@ -1,4 +1,4 @@
-import { Agent as UndiciAgent, fetch as undiciFetch } from 'undici';
+import * as undici from 'undici';
import {
BackendJsonNode,
Category,
@@ -105,12 +105,12 @@ export class Backend {
}
private async fetchJson<T>(path: string, method: 'POST' | 'GET', json?: unknown): Promise<T> {
- const options: RequestInit = isRenderer
+ const options: RequestInit & undici.RequestInit = isRenderer
? { method, cache: 'no-cache' }
: {
method,
cache: 'no-cache',
- dispatcher: new UndiciAgent({
+ dispatcher: new undici.Agent({
bodyTimeout: 0,
headersTimeout: 0,
}),
@@ -123,7 +123,7 @@ export class Backend {
};
options.signal = signal;
}
- const resp = await (isRenderer ? fetch : undiciFetch)(
+ const resp = await (isRenderer ? fetch : undici.fetch)(
`http://127.0.0.1:${this.port}${path}`,
options
); |
Fixes bug where CLI would crash if the chain took more than 5 minutes to process.
3bdf9c4
to
7269150
Compare
Hadn't realized that; npm shipped its own ESLint dependency, which seems to be the wrong version for this, and I wasn't aware that chaiNNer has its own, newer ESLint dependency in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Thank you @Splendide-Imaginarius!
Fixes bug where CLI would crash if the chain took more than 5 minutes to process.