-
Notifications
You must be signed in to change notification settings - Fork 615
[PERFORMANCE]: Use async I/O instead of blocking calls in async functions (S7493, S7487) #2164
Copy link
Copy link
Labels
bugSomething isn't workingSomething isn't workingperformancePerformance related itemsPerformance related itemspythonPython / backend development (FastAPI)Python / backend development (FastAPI)sonarSonarQube code quality findingsSonarQube code quality findings
Milestone
Description
Problem
15 locations use synchronous I/O operations inside async functions, blocking the event loop and degrading performance.
SonarQube Rules: python:S7493 (file I/O), python:S7487 (subprocess)
Severity: MAJOR
Sync File I/O (12 issues)
# BAD
async def load_data():
with open("file.json") as f:
return json.load(f)
# GOOD
async def load_data():
async with aiofiles.open("file.json") as f:
content = await f.read()
return json.loads(content)Affected Files
| File | Lines |
|---|---|
mcpgateway/cli_export_import.py |
145, 187 |
mcpgateway/services/grpc_service.py |
435, 437 |
mcpgateway/translate_grpc.py |
100, 102 |
mcpgateway/admin.py |
13263, 15861 |
mcpgateway/services/catalog_service.py |
76 |
plugins/external/clamav_server/clamav_plugin.py |
219 |
plugins/virus_total_checker/virus_total_checker.py |
561, 570 |
Sync Subprocess (3 issues)
# BAD
async def run_command():
result = subprocess.run(["cmd"], capture_output=True)
# GOOD
async def run_command():
proc = await asyncio.create_subprocess_exec("cmd", stdout=asyncio.subprocess.PIPE)
stdout, _ = await proc.communicate()Affected Files
| File | Lines |
|---|---|
mcpgateway/tools/builder/dagger_deploy.py |
416, 418, 420 |
Fix Strategy
- Add
aiofilesdependency if not present - Replace
open()withaiofiles.open() - Replace
subprocess.run()withasyncio.create_subprocess_exec() - For small files, consider using
asyncio.to_thread()as alternative
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingperformancePerformance related itemsPerformance related itemspythonPython / backend development (FastAPI)Python / backend development (FastAPI)sonarSonarQube code quality findingsSonarQube code quality findings