fix(lifecycle): abort HTTP before close

This commit is contained in:
edde746
2026-05-12 15:11:16 +02:00
parent bae127e459
commit 4577f26aa8
25 changed files with 1016 additions and 213 deletions
@@ -97,8 +97,8 @@ class _NotInSessionViewState extends State<_NotInSessionView> with MountedSetSta
String? get _plexDisplayName => context.read<ActiveProfileProvider>().active?.displayName;
Future<void> _checkHealth() async {
final client = HttpClient();
try {
final client = HttpClient();
client.connectionTimeout = const Duration(seconds: 5);
final request = await client.getUrl(Uri.parse(WatchTogetherPeerService.healthUrlFor(_customRelayUrl)));
final response = await request.close().namedTimeout(
@@ -106,13 +106,14 @@ class _NotInSessionViewState extends State<_NotInSessionView> with MountedSetSta
operation: 'WatchTogether health check',
);
final body = await response.transform(const SystemEncoding().decoder).join();
client.close();
if (!mounted) return;
setState(() => _healthOk = response.statusCode == 200 && body.trim() == 'ok');
} catch (e) {
appLogger.w('Watch Together health check failed', error: e);
if (!mounted) return;
setState(() => _healthOk = false);
} finally {
client.close(force: true);
}
}