Skip to content

fix: jaspr serve leaves the server process tree running after Ctrl+C on Windows (ports 8080 and 8181 stay in use) #916

Open

Description

@dunkmask2407

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

  1. Run jaspr serve -v in a static-mode project (Windows 11).
  2. Wait for Serving at http://localhost:8080. Do not edit anything.
  3. Press Ctrl+C once and answer y to Terminate batch job (Y/N)?.
  4. Run tasklist | findstr /I dart: the server processes are still there.
  5. Run jaspr serve -v again: 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, dartdevc or kernel_worker process 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 calls stop(), which copies and clears guards, then awaits them one after the other. For jaspr serve the order is: web compilers guard (Terminating web compilers... → ClientWorkflow.shutDown(): client.close(), devProxy.stop(), then it completes done), proxy server close, and the server kill (Terminating server...) last.
  • DevCommand.runCommand() ends with return await workflow.done, so it returns as soon as the web compilers guard completes. BaseCommand.run() then calls stop() a second time in its finally block. That call finds guards empty and returns immediately, so main reaches flushThenExit, which calls exit(), while the first stop() is still working through the remaining guards. If exit() wins, the proxy and server guards never run. This would match the missing Terminating server... line.
  • On Windows, Process.start in normal mode creates children with CREATE_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 jaspr through the pub shim (that is where Terminate batch job (Y/N)? comes from). I have not ruled out that answering y interrupts the shutdown. I will test with dart pub global run jaspr_cli:jaspr serve -v and 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

  1. added
    bug
    on Oct 4, 2026
  2. diegolopezrm commented on Oct 4, 2026

    @diegolopezrm
    Contributor

    Reproduced this on macOS, so it isn't Windows specific, Windows is just where it bites.

    Ran jaspr serve on one of the examples and sent the signal two ways:

    one SIGINT to the process group, what a real Ctrl+C in a terminal does
      Shutting down... / Stopping web compilers... / Terminating CSS runner...
      port free, nothing left behind
    
    one SIGINT to the CLI process only, closer to what you get on Windows
      Shutting down... / Stopping web compilers... / Terminating CSS runner...
      server VM still alive, still holding the port
    

    Same three lines both times, and Terminating server... never prints in either. That line comes from the guard watchProcess registers 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.pid file the CLI already writes, checking it at startup before binding.

    Happy to take this one if nobody else is on it.

  3. added a commit that references this issue on Oct 9, 2026
    4d6b28c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions