Flowise icon indicating copy to clipboard operation
Flowise copied to clipboard

[BUG] Socket timeout or read ECONNRESET

Open Hbmr9000 opened this issue 1 year ago • 3 comments

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

Hbmr9000 avatar Jul 02 '24 20:07 Hbmr9000

✨✨ 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

Details

Code analyzed at 90558ca688298ccba83b18d0b41c5d1a89e10916

AsharibAli avatar Jul 05 '24 10:07 AsharibAli

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

HenryHengZJ avatar Jul 11 '24 01:07 HenryHengZJ

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 ✨

AsharibAli avatar Jul 11 '24 16:07 AsharibAli

Updated to use SSE! Closing

HenryHengZJ avatar Sep 19 '24 12:09 HenryHengZJ