AOSSIE-Org / AOSSIE-Org/PictoPy

BUG: Sync-microservices: Health Check Blocks Main Event Loop (Performance Risk)

未关闭
#1,033 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
283
派生
679
平均合并
7 天 2 小时
30 天内合并 PR
3

描述

### Is there an existing issue for this?

- [x] I have searched the existing issues

### What happened?

### Description
The `/health` endpoint is defined as async, but it calls synchronous blocking database operations. This causes the entire FastAPI application to freeze for all users while the database check is performing I/O.

### How to reproduce
1. Simulate a slow database connection (e.g., lock the sqlite DB file).
2. Send a request to `GET /health`
3. Simultaneously try to hit `GET /watcher/status`
4. Observe that the status request hangs until the health check completes.

### Root cause
In `health.py`
```
@router.get("/health", response_model=HealthCheckResponse)
async def health_check():
# This function is blocking I/O!
db_status = db_check_database_connection()
return ...
```
And in `folders.py` `db_check_database_connection()` uses `sqlite3.connect()` , which is a synchronous blocking call. Using blocking code inside an async def function stops the asyncio loop.

### Video
On left = with async
On right = without async

https://github.com/user-attachments/assets/eccb75a5-f8aa-4a93-8ec0-325ead7aaac2

### Potential fix
- Simply define the route as `def health_check():` removing async, which tells FastAPI to run it in a separate thread automatically.
- Might use aiosqlite library instead

I will be happy to work on this issue

### Record

- [x] I agree to follow this project's Code of Conduct

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。