diff --git a/lib/providers/download_queue_provider.dart b/lib/providers/download_queue_provider.dart index 752e3dcd..9630382f 100644 --- a/lib/providers/download_queue_provider.dart +++ b/lib/providers/download_queue_provider.dart @@ -320,7 +320,6 @@ class DownloadQueueNotifier extends Notifier { final QueueProcessingGate _queueProcessingGate = QueueProcessingGate(); StreamSubscription>? _connectivitySub; int _downloadCount = 0; - static const _cleanupInterval = 50; static const _progressPollingInterval = Duration(milliseconds: 1200); static const _idleProgressPollEveryTicks = 3; static const _progressStreamBootstrapTimeout = Duration(seconds: 3); @@ -1897,17 +1896,18 @@ class DownloadQueueNotifier extends Notifier { await PlatformBridge.endBackgroundDownloadTask(); } - if (_downloadCount > 0) { - _log.d('Final connection cleanup...'); + if (stoppedWhilePaused && _downloadCount > 0) { try { await PlatformBridge.cleanupConnections(); } catch (e) { _log.e('Final cleanup failed: $e'); } - _downloadCount = 0; } + _downloadCount = 0; if (!stoppedWhilePaused) { + // Releasing idle runtimes already recycles the Rust HTTP pool. A + // separate cleanup immediately beforehand only builds it twice. await PlatformBridge.releaseNativeMemory(); } diff --git a/lib/providers/download_queue_provider_single_item.dart b/lib/providers/download_queue_provider_single_item.dart index 0f845ddc..561fad07 100644 --- a/lib/providers/download_queue_provider_single_item.dart +++ b/lib/providers/download_queue_provider_single_item.dart @@ -251,16 +251,9 @@ class _DownloadRun { } n._downloadCount++; - if (n._downloadCount % DownloadQueueNotifier._cleanupInterval == 0) { - _log.d( - 'Cleaning up idle connections (after ${n._downloadCount} downloads)...', - ); - try { - await PlatformBridge.cleanupConnections(); - } catch (e) { - _log.e('Connection cleanup failed: $e'); - } - } + // The HTTP pool expires idle connections itself. Keep warm connections + // for the next track; network changes/errors and queue teardown still + // recycle the pool when needed. } catch (e, stackTrace) { await _handleRunException(e, stackTrace); } finally {