From fc9e4bd58da7472be7cc9beb23e56287583b3205 Mon Sep 17 00:00:00 2001 From: Lewin Pauli Date: Fri, 13 Nov 2026 21:19:50 +0100 Subject: [PATCH 1/7] fix(cli): only stop build daemons this process started --- packages/jaspr/CHANGELOG.md | 1 + .../jaspr_cli/lib/src/dev/client_runner.dart | 34 +++++++++++++++---- packages/jaspr_cli/lib/src/dev/util.dart | 9 +++++ .../test/helpers/daemon_process_test.dart | 19 +++++++++++ 4 files changed, 56 insertions(+), 7 deletions(-) diff --git a/packages/jaspr/CHANGELOG.md b/packages/jaspr/CHANGELOG.md index ff7e0d6ac..7b0246cf4 100644 --- a/packages/jaspr/CHANGELOG.md +++ b/packages/jaspr/CHANGELOG.md @@ -18,6 +18,7 @@ - Fixed HTML duplication after hot-reload in client mode. - Fixed hot-reload losing changes when a new build starts before the previous reload has finished. - Fixed `jaspr serve` blocking all following reloads when a connected browser stops responding (e.g. a phone with the screen turned off). +- Fixed `jaspr build` and `jaspr serve` stopping a build daemon that another Jaspr process in the same directory started, which left that process serving empty 503 responses. - Fixed styles hot-reload recompiling all dependencies on every change on Windows. - Fixed key shortcuts in `jaspr serve` not working on Windows. diff --git a/packages/jaspr_cli/lib/src/dev/client_runner.dart b/packages/jaspr_cli/lib/src/dev/client_runner.dart index 7632274a7..ab4f31873 100644 --- a/packages/jaspr_cli/lib/src/dev/client_runner.dart +++ b/packages/jaspr_cli/lib/src/dev/client_runner.dart @@ -23,7 +23,7 @@ class ClientRunner { void startBuild() => client.startBuild(); - ClientRunner._(this.client, this.daemonPort, this.logger, [this.daemonPids = const []]) { + ClientRunner._(this.client, this.daemonPort, this.logger, this.daemonPids, {required this.ownsDaemon}) { client.shutdownNotifications.listen((data) { logger.write(data.message, tag: Tag.builder, level: Level.warning); if (data.failureType == 75) { @@ -33,6 +33,10 @@ class ClientRunner { }); } + /// Whether this process started the build daemon. A daemon that was already + /// running belongs to another Jaspr process and must not be stopped by us. + final bool ownsDaemon; + /// Starts the build daemon for development watching. static Future start( List buildOptions, @@ -40,26 +44,32 @@ class ClientRunner { void Function(FutureOr Function()) guard, ) async { var cancelled = false; + var ownsDaemon = false; late final CancelableOperation op; guard(() async { cancelled = true; if (!op.isCompleted) { op.cancel(); } - await util.stopDaemon(Directory.current.path); + if (ownsDaemon) { + await util.stopDaemon(Directory.current.path); + } }); op = CancelableOperation.fromFuture( Future(() async { final workingDirectory = Directory.current.path; + ownsDaemon = !await util.isDaemonRunning(workingDirectory); final client = await util.startBuildDaemon(workingDirectory, buildOptions, logger); if (client == null) return null; if (cancelled) { try { await client.close(); } catch (_) {} - await util.stopDaemon(workingDirectory); + if (ownsDaemon) { + await util.stopDaemon(workingDirectory); + } return null; } @@ -76,7 +86,7 @@ class ClientRunner { final daemonPort = util.daemonPort(workingDirectory); final daemonPids = await util.findPidsForPort(daemonPort); - final runner = ClientRunner._(client, daemonPort, logger, daemonPids); + final runner = ClientRunner._(client, daemonPort, logger, daemonPids, ownsDaemon: ownsDaemon); guard(() => runner.shutDown()); return runner; }), @@ -93,9 +103,14 @@ class ClientRunner { void Function(FutureOr Function())? guard, }) async { final workingDirectory = Directory.current.path; + // E.g. the daemon of a running `jaspr serve`. If its options don't match, + // connecting fails, and stopping it would break that other process. + final ownsDaemon = !await util.isDaemonRunning(workingDirectory); final client = await util.startBuildDaemon(workingDirectory, buildOptions, logger); if (client == null) { - await util.stopDaemon(workingDirectory); + if (ownsDaemon) { + await util.stopDaemon(workingDirectory); + } return 1; } @@ -106,7 +121,9 @@ class ClientRunner { try { await client.close(); } catch (_) {} - await util.stopDaemon(workingDirectory, knownPids: daemonPids); + if (ownsDaemon) { + await util.stopDaemon(workingDirectory, knownPids: daemonPids); + } } guard?.call(cleanUp); @@ -164,7 +181,10 @@ class ClientRunner { try { await client.close(); } catch (_) {} - await util.stopDaemon(Directory.current.path, knownPids: daemonPids); + // A shared daemon stops on its own once its last client disconnects. + if (ownsDaemon) { + await util.stopDaemon(Directory.current.path, knownPids: daemonPids); + } if (!_doneCompleter.isCompleted) _doneCompleter.complete(code); } } diff --git a/packages/jaspr_cli/lib/src/dev/util.dart b/packages/jaspr_cli/lib/src/dev/util.dart index 91d37e413..0c72ef294 100644 --- a/packages/jaspr_cli/lib/src/dev/util.dart +++ b/packages/jaspr_cli/lib/src/dev/util.dart @@ -61,6 +61,15 @@ Future startBuildDaemon(String workingDirectory, List isDaemonRunning(String workingDirectory) async { + final port = getDaemonPort(workingDirectory); + if (port == null) return false; + return (await findPidsForPort(port)).isNotEmpty; +} + /// Returns the port of the running daemon if the port file exists. int? getDaemonPort(String workingDirectory) { try { diff --git a/packages/jaspr_cli/test/helpers/daemon_process_test.dart b/packages/jaspr_cli/test/helpers/daemon_process_test.dart index 43d729703..a56614843 100644 --- a/packages/jaspr_cli/test/helpers/daemon_process_test.dart +++ b/packages/jaspr_cli/test/helpers/daemon_process_test.dart @@ -59,5 +59,24 @@ void main() { tempDir.deleteSync(recursive: true); } }); + + test('isDaemonRunning only reports a daemon that is listening on its port', () async { + final tempDir = Directory.systemTemp.createTempSync('daemon_running_test_'); + final server = await HttpServer.bind(InternetAddress.loopbackIPv4, 0); + final port = server.port; + try { + expect(await isDaemonRunning(tempDir.path), isFalse, reason: 'no port file'); + + Directory(daemonWorkspace(tempDir.path)).createSync(recursive: true); + File(portFilePath(tempDir.path)).writeAsStringSync('$port\ntoken'); + expect(await isDaemonRunning(tempDir.path), isTrue); + + await server.close(force: true); + expect(await isDaemonRunning(tempDir.path), isFalse, reason: 'leftover port file'); + } finally { + await server.close(force: true); + tempDir.deleteSync(recursive: true); + } + }); }); } From a7ed12d8630dad89358e9ea6a8ba9007c15c70cd Mon Sep 17 00:00:00 2001 From: Lewin Pauli Date: Fri, 13 Nov 2026 21:21:18 +0100 Subject: [PATCH 2/7] fix(cli): stop jaspr serve with an error when the build daemon exits unexpectedly --- packages/jaspr/CHANGELOG.md | 1 + .../jaspr_cli/lib/src/dev/client_runner.dart | 12 +++++ .../test/src/commands/serve_command_test.dart | 50 +++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/packages/jaspr/CHANGELOG.md b/packages/jaspr/CHANGELOG.md index 7b0246cf4..d5ade8918 100644 --- a/packages/jaspr/CHANGELOG.md +++ b/packages/jaspr/CHANGELOG.md @@ -19,6 +19,7 @@ - Fixed hot-reload losing changes when a new build starts before the previous reload has finished. - Fixed `jaspr serve` blocking all following reloads when a connected browser stops responding (e.g. a phone with the screen turned off). - Fixed `jaspr build` and `jaspr serve` stopping a build daemon that another Jaspr process in the same directory started, which left that process serving empty 503 responses. +- Fixed `jaspr serve` not noticing when its build daemon exits without a shutdown notification. It now stops with an error instead of answering every request with an empty 503. - Fixed styles hot-reload recompiling all dependencies on every change on Windows. - Fixed key shortcuts in `jaspr serve` not working on Windows. diff --git a/packages/jaspr_cli/lib/src/dev/client_runner.dart b/packages/jaspr_cli/lib/src/dev/client_runner.dart index ab4f31873..e132123fa 100644 --- a/packages/jaspr_cli/lib/src/dev/client_runner.dart +++ b/packages/jaspr_cli/lib/src/dev/client_runner.dart @@ -31,6 +31,18 @@ class ClientRunner { } shutDown(data.failureType); }); + // A daemon that is killed (e.g. by another process) sends no shutdown + // notification, the connection just closes. Without this, the proxy would + // keep answering every request with an empty 503. + client.finished.whenComplete(() { + if (_isShutDown) return; + logger.write( + 'The build daemon exited unexpectedly. Please restart Jaspr.', + tag: Tag.builder, + level: Level.critical, + ); + shutDown(1); + }).ignore(); } /// Whether this process started the build daemon. A daemon that was already diff --git a/packages/jaspr_cli/test/src/commands/serve_command_test.dart b/packages/jaspr_cli/test/src/commands/serve_command_test.dart index 0c305b26f..22bc4b9f4 100644 --- a/packages/jaspr_cli/test/src/commands/serve_command_test.dart +++ b/packages/jaspr_cli/test/src/commands/serve_command_test.dart @@ -74,6 +74,56 @@ void main() { }); }); + test('stops with an error when the build daemon exits without notice', () async { + await io.runZoned(() async { + io.setupFakeProject('myapp', mode: 'client'); + io.stubDartSDK(); + + final buildDaemon = io.setupFakeBuildDaemon(verifyArgs: buildRunnerDartArgs); + + final serveResult = runner.run(['serve', '--verbose']); + + await expectLater( + io.stdout.queue, + emitsInOrderWithTimeout([ + 'Starting myapp in client rendering mode.', + '[BUILDER] Starting web compilers...', + '[BUILDER] Connecting to the build daemon...', + '[BUILDER] Starting initial build...', + ]), + ); + + await io.runInitialBuild(buildDaemon); + + await expectLater( + io.stdout.queue, + emitsInOrderWithTimeout([ + '[BUILDER] Done building web assets.', + '[LOG] Serving at http://localhost:8080', + ]), + ); + + // E.g. killed by another Jaspr process: no ShutdownNotification, the + // connection just closes. + await buildDaemon.close(); + + await expectLater( + io.stderr.queue, + emitsInOrderWithTimeout([ + '[BUILDER] [CRITICAL] The build daemon exited unexpectedly. Please restart Jaspr.', + ]), + ); + await expectLater( + io.stdout.queue, + emitsInOrderWithTimeout([ + 'Stopping web compilers...', + ]), + ); + + expect(await serveResult, equals(1)); + }); + }); + test('handles keyboard shortcuts (r, R, d, l)', () async { await io.runZoned(() async { io.stdin.hasTerminalOverride = true; From e96c84d2cd79d607d449286c94e2b96c860403aa Mon Sep 17 00:00:00 2001 From: Lewin Pauli Date: Fri, 13 Nov 2026 21:35:40 +0100 Subject: [PATCH 3/7] test(cli): cover jaspr build leaving another process's build daemon running --- .../test/src/dev/client_runner_test.dart | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 packages/jaspr_cli/test/src/dev/client_runner_test.dart diff --git a/packages/jaspr_cli/test/src/dev/client_runner_test.dart b/packages/jaspr_cli/test/src/dev/client_runner_test.dart new file mode 100644 index 000000000..3c23a3893 --- /dev/null +++ b/packages/jaspr_cli/test/src/dev/client_runner_test.dart @@ -0,0 +1,57 @@ +import 'dart:convert'; +import 'dart:io'; + +import 'package:build_daemon/constants.dart'; +import 'package:jaspr_cli/src/dev/client_runner.dart'; +import 'package:jaspr_cli/src/dev/util.dart'; +import 'package:jaspr_cli/src/logging.dart'; +import 'package:path/path.dart' as p; +import 'package:test/test.dart'; + +void main() { + group('ClientRunner', () { + // Regression test for https://github.com/schultek/jaspr/issues/997. + // + // Uses real processes on purpose: the fakes connect through + // `connectUnchecked`, so `startBuildDaemon` never returns `null` there. + test('build does not stop a build daemon that another process started', () async { + final tempDir = Directory.systemTemp.createTempSync('client_runner_test_'); + + // Stands in for the build daemon of a running `jaspr serve`: a separate + // process listening on the port from the daemon's port file. + final script = File(p.join(tempDir.path, 'other_daemon.dart')) + ..writeAsStringSync(''' +import 'dart:io'; + +void main() async { + final server = await ServerSocket.bind(InternetAddress.loopbackIPv4, 0); + print(server.port); +} +'''); + final otherDaemon = await Process.start(Platform.resolvedExecutable, [script.path]); + addTearDown(() async { + otherDaemon.kill(); + await otherDaemon.exitCode; + tempDir.deleteSync(recursive: true); + }); + final port = int.parse( + await otherDaemon.stdout.transform(utf8.decoder).transform(const LineSplitter()).first, + ); + + Directory(daemonWorkspace(tempDir.path)).createSync(recursive: true); + File(portFilePath(tempDir.path)).writeAsStringSync('$port\ntoken'); + expect(await isDaemonRunning(tempDir.path), isTrue); + + // Connecting fails in the empty directory, which takes the same + // `client == null` path as an options skew with the other daemon. + final exitCode = await IOOverrides.runZoned( + () => ClientRunner.build(buildOptions: [], outputDir: 'build', logger: Logger(false)), + getCurrentDirectory: () => tempDir, + ); + + expect(exitCode, equals(1)); + expect(await isDaemonRunning(tempDir.path), isTrue, reason: 'the other daemon must keep running'); + expect(File(portFilePath(tempDir.path)).existsSync(), isTrue, reason: 'its port file must be kept'); + }); + }); +} From 23cb0290d4fc1e5a53f02f2af4521ce847f13c45 Mon Sep 17 00:00:00 2001 From: Lewin Pauli Date: Fri, 13 Nov 2026 21:35:48 +0100 Subject: [PATCH 4/7] fix(cli): don't report the build daemon as exited when stopping through the guards --- .../jaspr_cli/lib/src/dev/client_runner.dart | 11 ++-- .../test/src/commands/serve_command_test.dart | 58 +++++++++++++++++++ 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/packages/jaspr_cli/lib/src/dev/client_runner.dart b/packages/jaspr_cli/lib/src/dev/client_runner.dart index e132123fa..e50501662 100644 --- a/packages/jaspr_cli/lib/src/dev/client_runner.dart +++ b/packages/jaspr_cli/lib/src/dev/client_runner.dart @@ -57,13 +57,18 @@ class ClientRunner { ) async { var cancelled = false; var ownsDaemon = false; + ClientRunner? runner; late final CancelableOperation op; guard(() async { cancelled = true; if (!op.isCompleted) { op.cancel(); } - if (ownsDaemon) { + if (runner != null) { + // Shut the runner down before its daemon goes away, so that the + // closing connection is not reported as an unexpected exit. + await runner!.shutDown(); + } else if (ownsDaemon) { await util.stopDaemon(Directory.current.path); } }); @@ -98,9 +103,7 @@ class ClientRunner { final daemonPort = util.daemonPort(workingDirectory); final daemonPids = await util.findPidsForPort(daemonPort); - final runner = ClientRunner._(client, daemonPort, logger, daemonPids, ownsDaemon: ownsDaemon); - guard(() => runner.shutDown()); - return runner; + return runner = ClientRunner._(client, daemonPort, logger, daemonPids, ownsDaemon: ownsDaemon); }), ); diff --git a/packages/jaspr_cli/test/src/commands/serve_command_test.dart b/packages/jaspr_cli/test/src/commands/serve_command_test.dart index 22bc4b9f4..ce4280c05 100644 --- a/packages/jaspr_cli/test/src/commands/serve_command_test.dart +++ b/packages/jaspr_cli/test/src/commands/serve_command_test.dart @@ -1,7 +1,9 @@ import 'dart:convert'; import 'dart:io'; +import 'package:build_daemon/data/build_request.dart'; import 'package:build_daemon/data/build_status.dart'; +import 'package:build_daemon/data/build_target_request.dart'; import 'package:jaspr_cli/src/command_runner.dart'; import 'package:jaspr_cli/src/project.dart'; import 'package:mocktail/mocktail.dart'; @@ -124,6 +126,62 @@ void main() { }); }); + test('does not report the build daemon as exited unexpectedly when stopping after a failed build', () async { + await io.runZoned(() async { + io.setupFakeProject('myapp', mode: 'client'); + io.stubDartSDK(); + + final buildDaemon = io.setupFakeBuildDaemon(verifyArgs: buildRunnerDartArgs); + + // Stopping the daemon closes its connection, as a real daemon process + // that is killed would. The pid is never in use. + when(() => io.process.run('lsof', ['-tiTCP:1234', '-sTCP:LISTEN'])).thenAnswer((_) async { + await buildDaemon.close(); + return ProcessResult(0, 0, '2147483647\n', ''); + }); + + final serveResult = runner.run(['serve', '--verbose']); + + await expectLater( + io.stdout.queue, + emitsInOrderWithTimeout([ + 'Starting myapp in client rendering mode.', + '[BUILDER] Starting web compilers...', + '[BUILDER] Connecting to the build daemon...', + '[BUILDER] Starting initial build...', + ]), + ); + + await expectLater( + buildDaemon.messages, + emitsInOrderWithTimeout([ + isA(), + isA(), + ]), + ); + buildDaemon.sendMessage( + BuildResults((b) { + b.results.add( + DefaultBuildResult((b) { + b.target = 'web'; + b.status = BuildStatus.failed; + }), + ); + }), + ); + + // Stops through the guards, like Ctrl+C. + expect(await serveResult, equals(1)); + + final errors = []; + while (await io.stderr.queue.hasNext.timeout(const Duration(milliseconds: 300), onTimeout: () => false)) { + errors.add(await io.stderr.queue.next); + } + expect(errors, contains('[BUILDER] [ERROR] Could not start dev server due to build errors.')); + expect(errors, isNot(contains(contains('exited unexpectedly')))); + }); + }); + test('handles keyboard shortcuts (r, R, d, l)', () async { await io.runZoned(() async { io.stdin.hasTerminalOverride = true; From c21994b4deed4d94f3e0fa97e0295297c0f06b65 Mon Sep 17 00:00:00 2001 From: Lewin Pauli Date: Fri, 13 Nov 2026 21:43:20 +0100 Subject: [PATCH 5/7] fix(cli): never stop a build daemon on options or version skew, and probe its port directly --- .../jaspr_cli/lib/src/dev/client_runner.dart | 14 +++++-- packages/jaspr_cli/lib/src/dev/util.dart | 40 +++++++++++++++---- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/packages/jaspr_cli/lib/src/dev/client_runner.dart b/packages/jaspr_cli/lib/src/dev/client_runner.dart index e50501662..71ce7d907 100644 --- a/packages/jaspr_cli/lib/src/dev/client_runner.dart +++ b/packages/jaspr_cli/lib/src/dev/client_runner.dart @@ -78,8 +78,12 @@ class ClientRunner { final workingDirectory = Directory.current.path; ownsDaemon = !await util.isDaemonRunning(workingDirectory); - final client = await util.startBuildDaemon(workingDirectory, buildOptions, logger); - if (client == null) return null; + final (:client, :foreignDaemon) = await util.startBuildDaemon(workingDirectory, buildOptions, logger); + if (client == null) { + // A daemon that was still starting up when we checked. + if (foreignDaemon) ownsDaemon = false; + return null; + } if (cancelled) { try { await client.close(); @@ -121,9 +125,11 @@ class ClientRunner { // E.g. the daemon of a running `jaspr serve`. If its options don't match, // connecting fails, and stopping it would break that other process. final ownsDaemon = !await util.isDaemonRunning(workingDirectory); - final client = await util.startBuildDaemon(workingDirectory, buildOptions, logger); + final (:client, :foreignDaemon) = await util.startBuildDaemon(workingDirectory, buildOptions, logger); if (client == null) { - if (ownsDaemon) { + // `foreignDaemon` also covers a daemon that was still starting up when + // we checked. + if (ownsDaemon && !foreignDaemon) { await util.stopDaemon(workingDirectory); } return 1; diff --git a/packages/jaspr_cli/lib/src/dev/util.dart b/packages/jaspr_cli/lib/src/dev/util.dart index 0c72ef294..68c35a690 100644 --- a/packages/jaspr_cli/lib/src/dev/util.dart +++ b/packages/jaspr_cli/lib/src/dev/util.dart @@ -12,12 +12,21 @@ import '../process_runner.dart'; import '../project.dart'; /// Connects to the `build_runner` daemon. -Future startBuildDaemon(String workingDirectory, List buildOptions, Logger logger) async { +/// +/// [DaemonConnection.client] is `null` if connecting failed. +/// [DaemonConnection.foreignDaemon] is `true` if it failed because another +/// daemon with different options or another version is running in +/// [workingDirectory]. That daemon belongs to another process and must not be +/// stopped, even if it was still starting up when [isDaemonRunning] was checked. +Future startBuildDaemon(String workingDirectory, List buildOptions, Logger logger) async { logger.write('Connecting to the build daemon...', tag: Tag.builder, progress: ProgressState.running); final args = [dartExecutable, 'run', 'build_runner', 'daemon', ...buildOptions]; if (ProcessRunner.isDefault) { try { - return await BuildDaemonClient.connect(workingDirectory, args, logHandler: logger.writeServerLog); + return ( + client: await BuildDaemonClient.connect(workingDirectory, args, logHandler: logger.writeServerLog), + foreignDaemon: false, + ); } on OptionsSkew catch (e) { logger.write( 'Incompatible options with current running build daemon: ${e.details}\n\n' @@ -26,7 +35,7 @@ Future startBuildDaemon(String workingDirectory, List startBuildDaemon(String workingDirectory, List startBuildDaemon(String workingDirectory, List startBuildDaemon(String workingDirectory, List isDaemonRunning(String workingDirectory) async { final port = getDaemonPort(workingDirectory); if (port == null) return false; - return (await findPidsForPort(port)).isNotEmpty; + try { + final socket = await Socket.connect(InternetAddress.loopbackIPv4, port, timeout: const Duration(seconds: 2)); + socket.destroy(); + return true; + } on SocketException { + return false; + } } /// Returns the port of the running daemon if the port file exists. From 6cd7862eddf5dfa68713ff9843e51a119fadfcdf Mon Sep 17 00:00:00 2001 From: Lewin Pauli Date: Fri, 13 Nov 2026 21:43:28 +0100 Subject: [PATCH 6/7] fix(cli): stop jaspr serve when the build daemon exits during the initial build --- .../jaspr_cli/lib/src/dev/dev_workflow.dart | 10 +++++ .../test/src/commands/serve_command_test.dart | 40 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/packages/jaspr_cli/lib/src/dev/dev_workflow.dart b/packages/jaspr_cli/lib/src/dev/dev_workflow.dart index 398354c63..620ed7398 100644 --- a/packages/jaspr_cli/lib/src/dev/dev_workflow.dart +++ b/packages/jaspr_cli/lib/src/dev/dev_workflow.dart @@ -345,6 +345,16 @@ class DevWorkflow { } }); + // Also stop waiting when the build daemon goes away before the initial + // build completes. The listener that propagates `clientRunner.done` to the + // workflow is only installed after this wait. + clientRunner.done.then((_) { + if (!initialBuildCompleter.isCompleted) { + aborted = true; + initialBuildCompleter.completeError(Object()); + } + }); + clientRunner.startBuild(); final BuildResult initialResult; diff --git a/packages/jaspr_cli/test/src/commands/serve_command_test.dart b/packages/jaspr_cli/test/src/commands/serve_command_test.dart index ce4280c05..9658996fe 100644 --- a/packages/jaspr_cli/test/src/commands/serve_command_test.dart +++ b/packages/jaspr_cli/test/src/commands/serve_command_test.dart @@ -126,6 +126,46 @@ void main() { }); }); + test('stops with an error when the build daemon exits during the initial build', () async { + await io.runZoned(() async { + io.setupFakeProject('myapp', mode: 'client'); + io.stubDartSDK(); + + final buildDaemon = io.setupFakeBuildDaemon(verifyArgs: buildRunnerDartArgs); + + final serveResult = runner.run(['serve', '--verbose']); + + await expectLater( + io.stdout.queue, + emitsInOrderWithTimeout([ + 'Starting myapp in client rendering mode.', + '[BUILDER] Starting web compilers...', + '[BUILDER] Connecting to the build daemon...', + '[BUILDER] Starting initial build...', + ]), + ); + + await expectLater( + buildDaemon.messages, + emitsInOrderWithTimeout([ + isA(), + isA(), + ]), + ); + + // Gone before the first build result, without a notification. + await buildDaemon.close(); + + await expectLater( + io.stderr.queue, + emitsInOrderWithTimeout([ + '[BUILDER] [CRITICAL] The build daemon exited unexpectedly. Please restart Jaspr.', + ]), + ); + expect(await serveResult.timeout(const Duration(seconds: 10)), equals(1)); + }); + }); + test('does not report the build daemon as exited unexpectedly when stopping after a failed build', () async { await io.runZoned(() async { io.setupFakeProject('myapp', mode: 'client'); From a35856a6fb4cc0af9e345cdc8fba708625d365e7 Mon Sep 17 00:00:00 2001 From: Lewin Pauli Date: Wed, 18 Nov 2026 13:45:37 +0100 Subject: [PATCH 7/7] docs: move the changelog entries to the unreleased section --- packages/jaspr/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/jaspr/CHANGELOG.md b/packages/jaspr/CHANGELOG.md index 76336202b..22885e1b8 100644 --- a/packages/jaspr/CHANGELOG.md +++ b/packages/jaspr/CHANGELOG.md @@ -4,6 +4,8 @@ - Fixed a server built with `dart build cli` on Linux with Dart 3.14 or later not finding its `web` directory and failing with "Could not resolve project directory containing pubspec.yaml" when no `pubspec.yaml` is above it. Since Dart 3.14 such a bundle keeps the snapshot in `lib/libdartaot.so`, which `Platform.script` points at. - Fixed `jaspr serve` with Flutter embedding or plugins failing on Flutter 3.50, which moved the precompiled DDC SDK to `kernel/ddc/canary` and `kernel/ddc/stable`. +- Fixed `jaspr build` and `jaspr serve` stopping a build daemon that another Jaspr process in the same directory started, which left that process serving empty 503 responses. +- Fixed `jaspr serve` not noticing when its build daemon exits without a shutdown notification. It now stops with an error instead of answering every request with an empty 503. ## 0.24.0-beta.1 @@ -21,8 +23,6 @@ - Fixed HTML duplication after hot-reload in client mode. - Fixed hot-reload losing changes when a new build starts before the previous reload has finished. - Fixed `jaspr serve` blocking all following reloads when a connected browser stops responding (e.g. a phone with the screen turned off). -- Fixed `jaspr build` and `jaspr serve` stopping a build daemon that another Jaspr process in the same directory started, which left that process serving empty 503 responses. -- Fixed `jaspr serve` not noticing when its build daemon exits without a shutdown notification. It now stops with an error instead of answering every request with an empty 503. - Fixed styles hot-reload recompiling all dependencies on every change on Windows. - Fixed key shortcuts in `jaspr serve` not working on Windows.