From 8a9f3316eadaf2d34b91ed12d567b1a2c9b5cacf Mon Sep 17 00:00:00 2001 From: GT610 Date: Wed, 10 Jun 2026 12:14:54 +0800 Subject: [PATCH] fix: resolve final 4 bugs before convergence MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug fixes: - Aria2RpcClient.close(): completeError all pending completers with ConnectionFailedException before clearing (callers were hanging 10s then getting wrong TimeoutException instead) - TaskActionDialogs: fix double-counting in outer catch — subtract already-counted success/skipped from remaining tasks.length - TaskDetailsDialog: add outerContext.mounted guard before accessing outerContext.read() in timer callback (prevents crash if underlying page is disposed while timer fires) - BuiltinInstanceService._buildArgs: use _resolveEffectiveDhtListenPort for --dht-listen-port instead of raw settings value (ensures valid port range 1-65535 and handles String→int parsing, matching UPnP port resolution) --- lib/pages/download_page/components/task_action_dialogs.dart | 2 +- lib/pages/download_page/components/task_details_dialog.dart | 1 + lib/services/aria2_rpc_client.dart | 5 +++++ lib/services/builtin_instance_service.dart | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/pages/download_page/components/task_action_dialogs.dart b/lib/pages/download_page/components/task_action_dialogs.dart index 2c5ffa1..add288e 100644 --- a/lib/pages/download_page/components/task_action_dialogs.dart +++ b/lib/pages/download_page/components/task_action_dialogs.dart @@ -363,7 +363,7 @@ class TaskActionDialogs { error: e, stackTrace: stackTrace, ); - failCount += tasks.length; + failCount += tasks.length - successCount - skippedCount; } finally { client?.close(); } diff --git a/lib/pages/download_page/components/task_details_dialog.dart b/lib/pages/download_page/components/task_details_dialog.dart index 9ba5939..0dbcada 100644 --- a/lib/pages/download_page/components/task_details_dialog.dart +++ b/lib/pages/download_page/components/task_details_dialog.dart @@ -206,6 +206,7 @@ class TaskDetailsDialog { List>? peersResult; String? peersErrorLocal; try { + if (!outerContext.mounted) return; final instanceManager = outerContext .read(); final instance = instanceManager.getInstanceById( diff --git a/lib/services/aria2_rpc_client.dart b/lib/services/aria2_rpc_client.dart index dd9f4df..2784cf2 100644 --- a/lib/services/aria2_rpc_client.dart +++ b/lib/services/aria2_rpc_client.dart @@ -597,6 +597,11 @@ class Aria2RpcClient with Loggable { _webSocketSubscription = null; _webSocket?.close(); _webSocket = null; + for (final completer in _pendingRequests.values) { + if (!completer.isCompleted) { + completer.completeError(ConnectionFailedException()); + } + } _pendingRequests.clear(); } else { _httpClient?.close(); diff --git a/lib/services/builtin_instance_service.dart b/lib/services/builtin_instance_service.dart index 6ba290f..8e638c0 100644 --- a/lib/services/builtin_instance_service.dart +++ b/lib/services/builtin_instance_service.dart @@ -329,7 +329,7 @@ class BuiltinInstanceService with Loggable { '--bt-load-saved-metadata=${settings['btLoadSavedMetadata'] ?? true}', '--bt-seed-unverified=${settings['keepSeeding'] ?? false}', '--listen-port=$btListenPort', - '--dht-listen-port=${settings['dhtListenPort'] ?? 26701}', + '--dht-listen-port=${_resolveEffectiveDhtListenPort(settings)}', '--enable-dht6=${settings['enableDht6'] ?? true}', '--conf-path=$_aria2ConfPath', '--save-session=$sessionPath',