diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000000..9e39ee68e1 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2025-01-31 - [Async Event Loop Blocking] +**Learning:** Using synchronous `time.sleep()` inside `async` Python functions blocks the event loop, degrading concurrency and performance for all other asynchronous operations. +**Action:** Always replace `time.sleep()` with non-blocking `await asyncio.sleep()` in any `async def` functions. diff --git a/api/mcp_servers_apply.py b/api/mcp_servers_apply.py index 7ea5275db5..75c390b529 100644 --- a/api/mcp_servers_apply.py +++ b/api/mcp_servers_apply.py @@ -1,3 +1,4 @@ +import asyncio import time from helpers.api import ApiHandler, Request, Response @@ -15,7 +16,7 @@ async def process(self, input: dict[Any, Any], request: Request) -> dict[Any, An set_settings_delta({"mcp_servers": "[]"}) # to force reinitialization set_settings_delta({"mcp_servers": mcp_servers}) - time.sleep(1) # wait at least a second + await asyncio.sleep(1) # wait at least a second # MCPConfig.wait_for_lock() # wait until config lock is released status = MCPConfig.get_instance().get_servers_status() return {"success": True, "status": status} diff --git a/plugins/_code_execution/helpers/shell_ssh.py b/plugins/_code_execution/helpers/shell_ssh.py index 9aa9b4706a..f2ad37cbd2 100644 --- a/plugins/_code_execution/helpers/shell_ssh.py +++ b/plugins/_code_execution/helpers/shell_ssh.py @@ -73,7 +73,7 @@ async def connect(self, keepalive_interval: int = 5): full, part = await self.read_output() if full and not part: return - time.sleep(0.1) + await asyncio.sleep(0.1) except Exception as e: errors += 1 @@ -83,7 +83,7 @@ async def connect(self, keepalive_interval: int = 5): type="info", content=f"SSH Connection attempt {errors}...", ) - time.sleep(5) + await asyncio.sleep(5) else: raise e