diff --git a/app/lib/services/sockets/composite_transcription_socket.dart b/app/lib/services/sockets/composite_transcription_socket.dart index 4b6e992c59c..69358e2f50b 100644 --- a/app/lib/services/sockets/composite_transcription_socket.dart +++ b/app/lib/services/sockets/composite_transcription_socket.dart @@ -90,9 +90,13 @@ class CompositeTranscriptionSocket implements IPureSocket { CustomSttLogService.instance.info('Composite', 'Disconnecting...'); DebugLogManager.logEvent('composite_socket_disconnecting', {}); + // Mark disconnected before touching the children: their disconnect() + // fires onClosed, which would otherwise hit _onSocketClosed while the + // composite still looks connected and trigger a spurious + // "socket closed unexpectedly" teardown on top of this intentional one. + _status = PureSocketStatus.disconnected; await _disconnectBothQuietly(); - _status = PureSocketStatus.disconnected; onClosed(); } @@ -101,9 +105,9 @@ class CompositeTranscriptionSocket implements IPureSocket { CustomSttLogService.instance.info('Composite', 'Stopping...'); DebugLogManager.logEvent('composite_socket_stopping', {}); - await Future.wait([primarySocket.stop(), secondarySocket.stop()]); - + // Same ordering requirement as disconnect(). _status = PureSocketStatus.disconnected; + await Future.wait([primarySocket.stop(), secondarySocket.stop()]); } /// Called when either socket closes unexpectedly