mirror of
https://github.com/open-webui/mcpo.git
synced 2026-11-05 01:27:39 +00:00
[PR #162] [MERGED] Gracefully shutdown uvicorn.Server on task cancellation in run() #191
Labels
No labels
bug
can't reproduce
documentation
enhancement
good first issue
help wanted
invalid
pull-request
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
open-webui/mcpo#191
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/mcpo/pull/162
Author: @021gink
Created: 5/28/2025
Status: ✅ Merged
Merged: 6/6/2025
Merged by: @tjbck
Base:
main← Head:graceful-uvicorn-shutdown📝 Commits (1)
101c513Gracefully shutdown uvicorn.Server on task cancellation in run()📊 Changes
1 file changed (+7 additions, -1 deletions)
View changed files
📝
src/mcpo/main.py(+7 -1)📄 Description
Summary
This PR updates the
run()function to properly shut down theuvicorn.Serverwhen the task is cancelled viatask.cancel().Motivation
Previously, cancelling the task running
run()did not stop theuvicornserver, leaving the socket bound to the port and causing issues when trying to restart or cleanly terminate the server. This change handlesasyncio.CancelledErrorand triggersserver.should_exit = Trueandawait server.shutdown()to release resources.Changes
try/except asyncio.CancelledErrorblock aroundserver.serve()server.should_exitis set andserver.shutdown()is awaited before re-raising the cancellationTesting
Tested locally by launching
run()viaasyncio.create_task()and then cancelling it. Confirmed that the uvicorn server exits cleanly and releases the port.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.