fix: run blocking verify calls in threadpool#296
Conversation
Moves verify_repo and _scan_repo_dir calls in the /verify endpoint to run_in_threadpool so they no longer block the event loop while processing. Fixes ionfwsrijan#224.
|
🎉 Thank you @asnaassalam for submitting a Pull Request! We're excited to review your contribution. Before Review✅ Ensure all CI checks pass ⚡ Want faster reviews and contributor support? Join our Discord community: 🔗 https://discord.gg/FcXuyw2Rs Maintainers and mentors are active there and can help resolve blockers quickly. Happy Contributing! 🚀 |
|
✅ PR template check passed! @arpit2006 this PR is ready for your review. 🚀 |
There was a problem hiding this comment.
Pull request overview
This PR fixes a scalability/performance bug in the backend by preventing the async /verify FastAPI route from executing long-running synchronous verification and scanning work on the main event loop thread.
Changes:
- Offloaded
verify_repo(repo_dir)from the/verifyasync route intorun_in_threadpool. - Offloaded
_scan_repo_dir(...)from the/verifyasync route intorun_in_threadpool(viafunctools.partial), matching existing patterns inmain.py.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@asnaassalam , Please Resolve CI issue! |
|
✅ PR template check passed! @arpit2006 this PR is ready for your review. 🚀 |
|
@asnaassalam , CI issue |
Linked issue
Closes #224
What this PR does
The /verify endpoint called verify_repo() and _scan_repo_dir() directly inside an async route. Both are blocking (synchronous) calls, so they occupied the single event loop for their full duration freezing all other requests until verification finished. This PR wraps both calls in run_in_threadpool so they run in a separate thread instead of blocking the main event loop.
Type of change
ML tier (if applicable)
Stack affected
Changes
Backend
Frontend
New dependencies
Database / schema changes
Testing
How did you test this?
Checklist
console.erroror unhandled Python exceptions introducedrequirements.txt/package.jsonupdated if new dependencies added.pkl,.pt, etc.) are gitignored, not committedAnything reviewers should focus on
Followed the same run_in_threadpool + functools.partial pattern already used elsewhere in main.py for consistency. Please confirm this doesn't introduce any thread-safety issues in verify_repo or _scan_repo_dir.
Screenshots (if UI changed)
N/A (Backend-only changes)