[BUG] Socket timeout or read ECONNRESET
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 [31m[llm/error][39m [[90m1:chain:LLMChain > [1m2:llm:ChatOpenAI[22m[39m] [78.86s] LLM run errored with error: "read ECONNRESET\n\nError: read ECONNRESET\n at TLSWrap.onStreamRead (node:internal/stream_base_commons:218:20)" [31m[chain/error][39m [[90m[1m1:chain:LLMChain[22m[39m] [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)
[31m[llm/error][39m [[90m1:chain:LLMChain > [1m2:llm:ChatOpenAI[22m[39m] [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)" [31m[chain/error][39m [[90m[1m1:chain:LLMChain[22m[39m] [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
- Installation [npx flowise start]
- Flowise Version [1.8.3]
- OS: macOS, Windows, Linux]
- running api calls from a jupyter notebook
- Browser [safari] <-- shouldn't matter
✨✨ 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.tsdoes 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.tsat lines 227 and 493. - The
createPredictionfunction inpackages/server/src/controllers/predictions/index.tsdoes not implement any retry mechanism for ECONNRESET or Socket timeout errors. - The current implementation only logs the errors and throws an
InternalFlowiseErrorwithout retrying the API call.
After
- Yes, the API call is now automatically retried after an ECONNRESET or Socket timeout error. 🔄
- Added retry logic in
utilBuildChatflowfunction inpackages/server/src/utils/buildChatflow.tsto 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
createPredictionfunction inpackages/server/src/controllers/predictions/index.tsto utilize the retry logic for ECONNRESET and Socket timeout errors. - Errors are now logged, and if retries are exhausted, an
InternalFlowiseErroris thrown.
Plan
packages/server/src/utils/buildChatflow.ts(CHANGE)- Add retry logic in
utilBuildChatflowfunction 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
- Add retry logic in
packages/server/src/controllers/predictions/index.ts(CHANGE)- Update
createPredictionfunction to utilize the retry logic for ECONNRESET and Socket timeout errors
- Update
Sketch of implementation
Details
Code analyzed at 90558ca688298ccba83b18d0b41c5d1a89e10916
this looks like an issue with SocketIO, we are in the process of changing to Server Side Event that hopefully can solve the issue
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 ✨
Updated to use SSE! Closing