Repository navigation
Description
Description
On Windows, after a normal jaspr serve session, pressing Ctrl+C leaves the server process tree running (the Dart VM running server_target.dart and its dds_aot service). The CLI exits after printing Terminating web compilers...; the Terminating server... line never appears. The next jaspr serve then fails to bind ports 8080 and 8181 until I kill the processes by hand.
This is deterministic. It happens with no file edits, no build errors and no hung build: I start the server, wait for it to be ready, and press Ctrl+C.
Steps To Reproduce
- Run
jaspr serve -vin a static-mode project (Windows 11). - Wait for
Serving at http://localhost:8080. Do not edit anything. - Press Ctrl+C once and answer
ytoTerminate batch job (Y/N)?. - Run
tasklist | findstr /I dart: the server processes are still there. - Run
jaspr serve -vagain: it fails to bind the ports.
Output of step 3:
Shutting down...
Terminating web compilers...
Terminate batch job (Y/N)? y
Processes still running after step 3 (Get-CimInstance Win32_Process; the two VS Code Dart extension processes, language-server and tooling-daemon, are left out):
PID Parent Name MB CommandLine
9440 1508 dart.exe 11 dart.exe --enable-vm-service --enable-asserts -Djaspr.flags.verbose=false ...\.dart_tool/jaspr/server_target.dart
1316 9440 dartvm.exe 451 dartvm.exe ... --enable-vm-service --enable-asserts ... server_target.dart
2052 1316 dartaotruntime.exe 29 dartaotruntime.exe ...\snapshots\dds_aot.dart.snapshot --vm-service-uri=http://127.0.0.1:55693/... --bind-address=localhost --bind-port=8181 --serve-devtools
Output of step 5 (the orphaned server still holds both ports):
[SERVER] [ERROR] Could not start the VM service: DartDevelopmentServiceException: Failed to create server socket (Only one usage of each socket address (protocol/network address/port) is normally permitted): 127.0.0.1:8181
[SERVER] [ERROR] Unhandled exception:
[SERVER] [ERROR] SocketException: Failed to create server socket (OS Error: Only one usage of each socket address (protocol/network address/port) is normally permitted, errno = 10048), address = 0.0.0.0, port = 8080
[SERVER] [ERROR] #5 ServerApp._createServer (package:jaspr/src/server/server_app.dart:84:21)
[SERVER] [ERROR] #6 ServerApp._run (package:jaspr/src/server/server_app.dart:47:30)
[CLI] [ERROR] Server stopped unexpectedly. There is probably more output above.
Doctor Output
[✓] Jaspr CLI (Version 0.23.5)
• Dart Version 3.13.4 (stable) (Tue Sep 15 01:01:15 2026 -0700) on "windows_x64" at C:\Dev\flutter\bin\cache\dart-sdk\bin\dart.exe
• Running on windows "Windows 11 Pro" 10.0 (Build 26200) - Locale en-US
• Analytics: Enabled
[✓] Current Project
• Dependencies on core packages:
• jaspr: ^0.23.5
• jaspr_builder: ^0.23.5 (dev)
• jaspr_router: ^0.9.0
• Rendering mode: static
• Flutter mode: none
Expected Behavior
Ctrl+C should stop every process started by jaspr serve, including the server VM and its DDS, before the CLI exits, so that jaspr serve can be restarted right away.
Additional Context
What the test above shows:
- The build daemon tree is stopped correctly in this case: no
build_runner,build.dart.aot,dartdevcorkernel_workerprocess is left. Only the server tree survives. - The server launcher (PID 9440) is itself still alive. If
process.kill()had run on it, I would expect it to be gone, so the kill step seems to never run. - The launcher's parent (PID 1508) is not a Dart process, so the CLI process itself looks gone.
What I found reading jaspr_cli 0.23.5 (main and stable are identical for this package). I read the code but did not debug or execute it, so this is a hypothesis:
BaseCommand.shutdown()is called from the SIGINT listener without being awaited. It callsstop(), which copies and clearsguards, then awaits them one after the other. Forjaspr servethe order is: web compilers guard (Terminating web compilers...→ClientWorkflow.shutDown():client.close(),devProxy.stop(), then it completesdone), proxy server close, and the server kill (Terminating server...) last.DevCommand.runCommand()ends withreturn await workflow.done, so it returns as soon as the web compilers guard completes.BaseCommand.run()then callsstop()a second time in itsfinallyblock. That call findsguardsempty and returns immediately, somainreachesflushThenExit, which callsexit(), while the firststop()is still working through the remaining guards. Ifexit()wins, the proxy and server guards never run. This would match the missingTerminating server...line.- On Windows,
Process.startin normal mode creates children withCREATE_NO_WINDOW(runtime/bin/process_win.cc), so I believe they do not receive the console's Ctrl+C and need an explicit kill. On Linux and macOS the terminal sends SIGINT to the whole process group, which would hide the problem. I have not tested either point. - I start
jasprthrough the pub shim (that is whereTerminate batch job (Y/N)?comes from). I have not ruled out that answeringyinterrupts the shutdown. I will test withdart pub global run jaspr_cli:jaspr serve -vand update this issue.
A possible direction: keep the Future returned by shutdown() and make run() await it instead of calling stop() again, and consider killing the whole process tree on Windows. The next branch has a clearer message when a port is already in use, which helps diagnosis but does not address the cause.
Workaround I use (kills Jaspr's processes only, not the VS Code Dart extension's):
Get-CimInstance Win32_Process | Where-Object { $_.Name -like 'dart*' -and $_.CommandLine -match 'entrypoint/build\.dart\.aot|build_runner|server_target\.dart|dartdevc|kernel_worker|dds_aot' } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }I will file the separate case of a hung build (where the build daemon tree is also left behind) in another issue.
Activity
diegolopezrm commentedon Oct 4, 2026
Reproduced this on macOS, so it isn't Windows specific, Windows is just where it bites.
Ran
jaspr serveon one of the examples and sent the signal two ways:Same three lines both times, and
Terminating server...never prints in either. That line comes from the guardwatchProcessregisters for the server process, which is the last one registered, so the shutdown isn't reaching it. On macOS and Linux you never notice because the signal already killed the server through the process group. On Windows nothing else kills it, so it stays. I didn't pin down whether an earlier guard stalls or the process just exits first.Two directions if they're useful: have the shutdown finish its guard list before the process exits, or stop depending on that and use the
.dart_tool/jaspr/server.pidfile the CLI already writes, checking it at startup before binding.Happy to take this one if nobody else is on it.
Kill the server process when the CLI shuts down