FlowiseAI / Flowise

Drag & drop UI to build your customized LLM flow
https://flowiseai.com
Apache License 2.0
28k stars 14.42k forks source link

[BUG] Socket timeout or read ECONNRESET #2755

Open Hbmr9000 opened 3 weeks ago

Hbmr9000 commented 3 weeks ago

Describe the bug Im running 2xx api calls from python to flowise1.8.3. running on macOS. after some time (10mins) or so, i received now once an ECONNRESET error and once a Socket timeout. upon resending the api call, the service behaves normally

To Reproduce Steps to reproduce the behavior:

running some 100 api calls in a loop

Expected behavior i would expect, that the api call would be automatically triggered again after the failures.

service logs [llm/error] [1:chain:LLMChain > 2:llm:ChatOpenAI] [78.86s] LLM run errored with error: "read ECONNRESET\n\nError: read ECONNRESET\n at TLSWrap.onStreamRead (node:internal/stream_base_commons:218:20)" [chain/error] [1:chain:LLMChain] [78.87s] Chain run errored with error: "read ECONNRESET\n\nError: read ECONNRESET\n at TLSWrap.onStreamRead (node:internal/stream_base_commons:218:20)" 2024-07-02 22:03:33 [ERROR]: read ECONNRESET Error: read ECONNRESET at TLSWrap.onStreamRead (node:internal/stream_base_commons:218:20) 2024-07-02 22:03:33 [ERROR]: [server]: Error: Error: read ECONNRESET Error: Error: read ECONNRESET at buildFlow (/usr/local/lib/node_modules/flowise/dist/utils/index.js:493:19) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async utilBuildChatflow (/usr/local/lib/node_modules/flowise/dist/utils/buildChatflow.js:227:36) at async Object.buildChatflow (/usr/local/lib/node_modules/flowise/dist/services/predictions/index.js:9:28) at async createPrediction (/usr/local/lib/node_modules/flowise/dist/controllers/predictions/index.js:48:33)


[llm/error] [1:chain:LLMChain > 2:llm:ChatOpenAI] [972.24s] LLM run errored with error: "Socket timeout\n\nError: Socket timeout\n at TLSSocket.onTimeout (/usr/local/lib/node_modules/flowise/node_modules/agentkeepalive/lib/agent.js:350:23)\n at TLSSocket.emit (node:events:531:35)\n at Socket._onTimeout (node:net:590:8)\n at listOnTimeout (node:internal/timers:573:17)\n at process.processTimers (node:internal/timers:514:7)" [chain/error] [1:chain:LLMChain] [972.24s] Chain run errored with error: "Socket timeout\n\nError: Socket timeout\n at TLSSocket.onTimeout (/usr/local/lib/node_modules/flowise/node_modules/agentkeepalive/lib/agent.js:350:23)\n at TLSSocket.emit (node:events:531:35)\n at Socket._onTimeout (node:net:590:8)\n at listOnTimeout (node:internal/timers:573:17)\n at process.processTimers (node:internal/timers:514:7)" 2024-07-02 19:21:06 [ERROR]: Socket timeout Error: Socket timeout at TLSSocket.onTimeout (/usr/local/lib/node_modules/flowise/node_modules/agentkeepalive/lib/agent.js:350:23) at TLSSocket.emit (node:events:531:35) at Socket._onTimeout (node:net:590:8) at listOnTimeout (node:internal/timers:573:17) at process.processTimers (node:internal/timers:514:7) 2024-07-02 19:21:06 [ERROR]: [server]: Error: Error: Socket timeout Error: Error: Socket timeout at buildFlow (/usr/local/lib/node_modules/flowise/dist/utils/index.js:493:19) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async utilBuildChatflow (/usr/local/lib/node_modules/flowise/dist/utils/buildChatflow.js:227:36) at async Object.buildChatflow (/usr/local/lib/node_modules/flowise/dist/services/predictions/index.js:9:28) at async createPrediction (/usr/local/lib/node_modules/flowise/dist/controllers/predictions/index.js:48:33)

Flow sample Chatflow.json Setup

AsharibAli commented 2 weeks ago

✨✨ Here's an AI-assisted sketch of how you might approach this issue saved by @AsharibAli using Copilot Workspace v0.22

Topic
Is the API call automatically retried after an ECONNRESET or Socket timeout error? 🔄
Before
* No, the API call is not automatically retried after an ECONNRESET or Socket timeout error. The code in `packages/server/src/utils/buildChatflow.ts` does not include any retry logic for these errors. * Errors like ECONNRESET and Socket timeout are logged but not handled for retries in `packages/server/src/utils/buildChatflow.ts` at lines 227 and 493. * The `createPrediction` function in `packages/server/src/controllers/predictions/index.ts` does not implement any retry mechanism for ECONNRESET or Socket timeout errors. * The current implementation only logs the errors and throws an `InternalFlowiseError` without retrying the API call.
After
* Yes, the API call is now automatically retried after an ECONNRESET or Socket timeout error. 🔄 * Added retry logic in `utilBuildChatflow` function in `packages/server/src/utils/buildChatflow.ts` to handle ECONNRESET and Socket timeout errors. * The retry mechanism attempts the API call up to 3 times with a delay of 2 seconds between each attempt. * Updated `createPrediction` function in `packages/server/src/controllers/predictions/index.ts` to utilize the retry logic for ECONNRESET and Socket timeout errors. * Errors are now logged, and if retries are exhausted, an `InternalFlowiseError` is thrown.
Plan
* `packages/server/src/utils/buildChatflow.ts` (CHANGE) - Add retry logic in `utilBuildChatflow` function to handle ECONNRESET and Socket timeout errors - Implement retry mechanism to attempt the API call up to 3 times with a delay of 2 seconds between each attempt * `packages/server/src/controllers/predictions/index.ts` (CHANGE) - Update `createPrediction` function to utilize the retry logic for ECONNRESET and Socket timeout errors
Sketch of implementation
[View the changes](https://copilot-workspace.githubnext.com/FlowiseAI/Flowise/issues/2755?shareId=d0c4c4a5-1d24-49c4-a770-49afa0f481b6)
Details
Code analyzed at 90558ca688298ccba83b18d0b41c5d1a89e10916
HenryHengZJ commented 1 week ago

this looks like an issue with SocketIO, we are in the process of changing to Server Side Event that hopefully can solve the issue

AsharibAli commented 1 week ago

this looks like an issue with SocketIO, we are in the process of changing to Server Side Event that hopefully can solve the issue

alright @HenryHengZJ ✨