Repository navigation
fix(cli): don't stop build daemons of other Jaspr processes, and stop serve when its daemon exits - #998
Conversation
Package Version ReportThe following packages have been updated: |
There was a problem hiding this comment.
🟡 Changes recommended
Unreliable daemon detection and premature ownership claims can delete or terminate another process’s daemon, while a disconnect during the initial build can leave serve hanging instead of exiting with an error.
3 open issues
What changed in this PR
Addresses the CLI regression from #928 reported in #997: commands could stop another Jaspr process’s build daemon, leaving jaspr serve returning empty 503 responses.
Changes:
- Adds daemon-liveness checks and ownership-based cleanup.
- Makes
servereport unexpected daemon disconnections and initiate shutdown with exit code 1. - Adds regression tests and changelog entries.
| File | Description |
|---|---|
packages/jaspr/CHANGELOG.md |
Documents the daemon lifecycle fixes. |
packages/jaspr_cli/test/src/commands/serve_command_test.dart |
Tests unexpected daemon disconnection after startup. |
packages/jaspr_cli/test/helpers/daemon_process_test.dart |
Tests liveness detection with missing, active, and stale port files. |
packages/jaspr_cli/lib/src/dev/util.dart |
Adds the daemon-liveness helper. |
packages/jaspr_cli/lib/src/dev/client_runner.dart |
Gates daemon cleanup on ownership and handles unexpected disconnections. |
Review effort: Balanced
|
The red |
…robe its port directly
d5d9a45 to
6cd7862
Compare


Fixes #997
Running
jaspr buildwhilejaspr serveruns in the same directory killed the serve's build daemon (OptionsSkew→stopDaemon(workingDirectory)).jaspr servedidn't notice and kept answering every request with an empty 503. This is a regression from the CLI refactor in #928. In 0.23.5,jaspr buildjust returned1.This PR has two fixes:
1. Only stop build daemons this process started
isDaemonRunning(workingDirectory)indev/util.dart. It probes the port from the daemon's port file withSocket.connecton loopback, so a leftover port file doesn't count, and a missing or failinglsof/netstatdoesn't make a running daemon look absent.ClientRunner.build()andClientRunner.start()check this before connecting and remember it asownsDaemon.stopDaemonis only called for a daemon this process started: on a failed connect, on cancel, in the guard, incleanUp()and inshutDown(). A daemon shared with another process stops on its own once its last client disconnects (_removeChannelin build_daemon), so nothing is left running.startBuildDaemonnow also reportsforeignDaemonwhen connecting fails withOptionsSkeworVersionSkew. In that case the daemon is never stopped, even if it was still starting up (no port file yet) when ownership was checked.jaspr serve. Its guard runs on every exit, so a secondjaspr servewith different options that fails withOptionsSkewkilled the other daemon in the same way.2. Stop
jaspr servewith an error when the build daemon exits unexpectedlyClientRunnernow also listens toclient.finished. If the connection closes without aShutdownNotificationand withoutshutDown()having been called, it logsThe build daemon exited unexpectedly. Please restart Jaspr.(critical) and shuts down with exit code 1. Before, serve kept proxying to a backend that no longer existed, andProxyHelperonly logged the connection error at verbose level.DevWorkflow.start()also stops waiting for the initial build whenclientRunner.donecompletes, so serve exits with 1 when the daemon goes away during the initial build, instead of waiting forever.ClientRunner.start()now shuts the runner down first. Before, on a failed initial build or Ctrl+C it stopped the daemon beforeshutDown()ran, and the closing connection would have been reported as an unexpected exit. The second guard that only calledshutDown()is removed, since the first one covers it.Tests:
daemon_process_test.dart:isDaemonRunningwith a listening port, without a port file and with a leftover port file.client_runner_test.dart:ClientRunner.build()runs in an empty temp directory whose port file points to a separate process standing in for the daemon of a runningjaspr serve. Connecting fails there, which takes the sameclient == nullpath asOptionsSkew. The test checks that the build returns1and that the other process keeps listening and keeps its port file. It uses real processes because the fakes connect throughconnectUnchecked, wherestartBuildDaemonnever returnsnull. This test fails without fix 1.serve_command_test.dart: the fake build daemon closes the connection without a notification. Serve must log the critical message and exit with 1. This test fails without fix 2.serve_command_test.dart: the daemon disconnects before the first build result. Serve must log the critical message and exit with 1. Without the change inDevWorkflow.start()the test times out.serve_command_test.dart: the initial build fails and serve stops through the guards, while stopping the daemon closes its connection, as a killed daemon process would. No unexpected exit may be reported. This test fails without the guard change in fix 2.OptionsSkew/VersionSkewpath: a real skew needs a full package withbuild_runnerand compiled builders, which felt too slow and flaky for CI.The failing
Test CLIjobs (cnen, cspn, smpn, snpn, vnen) fail onmainas well (e.g. run 43451833303):Prebuilt SDK file "dart_sdk.js" does not exist at …/flutter_web_sdk/kernel/ddcLibraryBundle-canvaskitwith Flutter 3.50. Withfail-fast, whichever fails first cancels the others.Type of Change
Ready Checklist
the semantic_changelog format.
///).