UvicornApp fails to reload with --reload flag present on Windows
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
The `AddUvicornApp` extension method was [recently updated](https://github.com/dotnet/aspire/blob/50d0b52d1bf0cb076e81c7233b53c7cf6d904424/src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs#L328) to add the `--reload` parameter when not in publish mode. The `--reload` parameter is successfully added, and uvicorn's logging indicates it does detect file changes, however it fails to reload the uvicorn app to apply the file changes after detecting them on my Windows device.
This is reproducing on the uvicorn app in the python playground project in this repository, so the repro steps use that.
Uvicorn's implementation for reloading after a change can be found here: [basereload.py](https://github.com/Kludex/uvicorn/blob/0391372376c264604a0475b0864bcbf3a8705352/uvicorn/supervisors/basereload.py#L88-L102). Uvicorn runs the python app in a child process and restarts it by sending a CTRL+C signal to it and starting a new process. It also relies on being able to write and flush a non-empty string to stdout to cause the signal to be sent properly. I'm not sure what fails here, but my guess is Aspire is preventing the signal from being sent properly.
### Expected Behavior
I expect that when I edit a python file in my uvicorn app, that the changes are detected and the app reloads successfully with those changes.
### Steps To Reproduce
1. Install `uv`
2. Clone and open `dotnet/aspire`
3. Run `./build.cmd`
4. Run `dotnet run --project .\playground\python\Python.AppHost\Python.AppHost.csproj`
5. Open the dashboard, find the URL for `uvicorn-app`, and test the `/health` endpoint to see "Healthy"
6. Edit [uvicorn_app/app.py](https://github.com/dotnet/aspire/blob/main/playground/python/uvicorn_app/app.py#L63) to make `/health` return "Healthier" and save
7. Open the console logs in the aspire dashboard for the `uvicorn-app` resource and notice the following log: `WatchFiles detected changes in 'app.py'. Reloading...`
8. Test the `/health` endpoint again, it will still show "Healthy"
9. Edit app.py again and notice that WatchFiles no longer detects more file changes
### Exceptions (if any)
_No response_
### .NET Version info
```
.NET SDK:
Version: 10.0.100-rc.2.25502.107
Commit: 89c8f6a112
Workload version: 10.0.100-manifests.e3b0c442
MSBuild version: 18.0.0-preview-25502-107+89c8f6a11
Runtime Environment:
OS Name: Windows
OS Version: 10.0.26200
OS Platform: Windows
RID: win-x64
Base Path: D:\src\aspire\.dotnet\sdk\10.0.100-rc.2.25502.107\
.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.
Host:
Version: 10.0.0-rc.1.25451.107
Architecture: x64
Commit: 2db1f5ee2b
.NET SDKs installed:
3.1.426 [c:\program files\dotnet\sdk]
6.0.321 [c:\program files\dotnet\sdk]
7.0.120 [c:\program files\dotnet\sdk]
8.0.121 [c:\program files\dotnet\sdk]
9.0.111 [c:\program files\dotnet\sdk]
9.0.304 [c:\program files\dotnet\sdk]
10.0.100-rc.1.25451.107 [c:\program files\dotnet\sdk]
10.0.100-rc.2.25502.107 [D:\src\aspire\.dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.32 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.16 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.26 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.36 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.20 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.19 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.20 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.21 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.8 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.9 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.10 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.0-rc.1.25451.107 [c:\program files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.32 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.16 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.15 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.26 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.36 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.20 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.19 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.20 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.21 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.1 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.8 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.9 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.10 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.0-rc.1.25451.107 [c:\program files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.32 [c:\program files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.16 [c:\program files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.15 [c:\program files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.26 [c:\program files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.36 [c:\program files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.20 [c:\program files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.19 [c:\program files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.20 [c:\program files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.21 [c:\program files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.8 [c:\program files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.9 [c:\program files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.10 [c:\program files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 10.0.0-rc.1.25451.107 [c:\program files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables:
Not set
global.json file:
D:\src\aspire\global.json
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
```
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.