From a5a1548c94bb9f1da41a1336eaace33e3d985f77 Mon Sep 17 00:00:00 2001 From: Codex Bot Date: Sun, 19 Apr 2026 13:37:58 +0200 Subject: [PATCH] Fix Windows local node daemon arguments --- lib/services/windows_local_node_service.dart | 53 ++++++++++++-------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/lib/services/windows_local_node_service.dart b/lib/services/windows_local_node_service.dart index 28465b0..5b603a4 100644 --- a/lib/services/windows_local_node_service.dart +++ b/lib/services/windows_local_node_service.dart @@ -39,20 +39,9 @@ class WindowsLocalNodeService implements LocalNodeService { @override Future stop() async { final effective = _resolveConfig(null); - final pidFile = File(await _pidFilePath()); - if (!await pidFile.exists()) { - _logger.w('Local node pidfile not found at ${pidFile.path}'); - return false; - } - final rawPid = await pidFile.readAsString(); - final pid = int.tryParse(rawPid.trim()); - if (pid == null) { - _logger.w('Local node pidfile invalid: $rawPid'); - return false; - } - final killed = Process.killPid(pid); - if (!killed) { - _logger.w('Failed to terminate local node process ($pid)'); + final stopped = await _stopViaRpc(effective); + if (!stopped) { + _logger.w('Failed to stop local node via RPC.'); return false; } return _waitForStop(effective); @@ -86,7 +75,6 @@ class WindowsLocalNodeService implements LocalNodeService { ); return false; } - final pidFile = await _pidFilePath(); final daemonLogFile = await AppPaths.localNodeLogFile(); final launcherLogFile = await AppPaths.localNodeLauncherLogFile(); await launcherLogFile.parent.create(recursive: true); @@ -97,8 +85,6 @@ class WindowsLocalNodeService implements LocalNodeService { config.rpcHost, '--rpc-bind-port', config.rpcPort.toString(), - '--pidfile', - pidFile, '--log-file', daemonLogFile.path, ...config.extraArgs, @@ -200,6 +186,35 @@ class WindowsLocalNodeService implements LocalNodeService { } } + Future _stopViaRpc(LocalNodeConfig config) async { + HttpClient? client; + try { + client = HttpClient(); + final uri = Uri.parse('http://${config.rpcHost}:${config.rpcPort}/json_rpc'); + final request = await client.postUrl(uri); + request.headers.contentType = ContentType.json; + request.write(jsonEncode({ + 'jsonrpc': '2.0', + 'id': '0', + 'method': 'stop_daemon', + })); + final response = await request.close(); + final body = await utf8.decoder.bind(response).join(); + if (response.statusCode != HttpStatus.ok) { + _logger.w( + 'Local node stop_daemon returned HTTP ${response.statusCode}: $body', + ); + return false; + } + return true; + } catch (error) { + _logger.w('Failed to call stop_daemon on local node: $error'); + return false; + } finally { + client?.close(force: true); + } + } + LocalNodeConfig _resolveConfig(LocalNodeConfig? config) { final base = config ?? _lastConfig ?? const LocalNodeConfig(); return _applyOverrides(base); @@ -252,8 +267,4 @@ class WindowsLocalNodeService implements LocalNodeService { } return null; } - - Future _pidFilePath() async { - return (await AppPaths.localNodePidFile()).path; - } }