fix(api/ontologies): offload blocking filesystem IO off the event loop#3070
Open
ly-wang19 wants to merge 1 commit into
Open
fix(api/ontologies): offload blocking filesystem IO off the event loop#3070ly-wang19 wants to merge 1 commit into
ly-wang19 wants to merge 1 commit into
Conversation
Contributor
|
Hello @ly-wang19, thank you for submitting a PR! We will respond as soon as possible. |
Vasilije1990
previously approved these changes
Jun 14, 2026
7ba3eb3 to
82a67c0
Compare
The delete_ontology and list_ontologies routes are async def but called the synchronous OntologyService methods directly, which perform blocking filesystem IO (stat/unlink, metadata read) on the event loop. The sibling upload_ontology route already awaits its async service method. Dispatch both synchronous calls via asyncio.to_thread. The service methods stay synchronous (their existing unit tests call them directly), so only the async routes change. Adds a regression test asserting each route offloads via asyncio.to_thread. Signed-off-by: ly-wang19 <ly-wang19@users.noreply.github.com>
82a67c0 to
cb8fb58
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The
delete_ontologyandlist_ontologiesontology routes areasync def, but call the synchronousOntologyServicemethods directly:Both service methods do blocking filesystem IO (
Path.exists/resolve/unlink, metadata read), so they stall the event loop for the duration. The siblingupload_ontologyroute alreadyawaits its async service method — these two were the inconsistent blocking paths.Change
Dispatch the two synchronous calls via
asyncio.to_thread. The service methods stay synchronous on purpose — their existing unit tests (tests/unit/api/test_delete_ontology.py) call them directly — so only the async routes change.Test
Adds
tests/unit/api/test_ontology_router_offload.py: extracts each route handler and asserts the blocking call is dispatched throughasyncio.to_thread. Reverting either offload fails the corresponding test.pytest tests/unit/api/test_ontology_router_offload.py tests/unit/api/test_delete_ontology.py→ 10 passed;ruffclean.