From 45eb6bc4534ff8eaa3b2d4fe6f02abe06416dead Mon Sep 17 00:00:00 2001 From: hailin Date: Wed, 25 Feb 2026 03:41:13 -0800 Subject: [PATCH] fix: use unawaited close to prevent WebSocket reconnect hang The await on sink.close() blocks indefinitely when the server doesn't respond to the close handshake. Use fire-and-forget with unawaited() so the new connection can proceed immediately. Co-Authored-By: Claude Opus 4.6 --- it0_app/lib/core/network/websocket_client.dart | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/it0_app/lib/core/network/websocket_client.dart b/it0_app/lib/core/network/websocket_client.dart index efed8bb..3596e79 100644 --- a/it0_app/lib/core/network/websocket_client.dart +++ b/it0_app/lib/core/network/websocket_client.dart @@ -30,16 +30,15 @@ class WebSocketClient { _lastPath = path; _lastToken = token; - // Close previous connection to prevent duplicate event delivery + // Close previous connection to prevent duplicate event delivery. + // Fire-and-forget: don't await close() as it can hang waiting for + // the server to acknowledge the close handshake. if (_channel != null) { _heartbeatTimer?.cancel(); - try { - await _channel!.sink.close(); - } catch (_) { - // Ignore errors when closing stale connections - } + final old = _channel!; _channel = null; _isConnected = false; + unawaited(old.sink.close().catchError((_) {})); } final uri = Uri.parse('$baseUrl$path');