jamiewest / signalr_core

ASP.NET Core SignalR Dart Client
https://pub.dev/packages/signalr_core
MIT License
90 stars 58 forks source link

BadState: Future already completed after calling _stopConnection #105

Closed junsiong2008 closed 7 months ago

junsiong2008 commented 9 months ago

Hey there, I am getting the following exception while trying to stop the connection occasionally: FlutterError - Bad state: Future already completed

To fix the error, you may add in a check before closing the connection in line 280 of 'src/http_connection.dart': From:

    if (_connectionState == ConnectionState.disconnecting) {
      // A call to stop() induced this call to stopConnection and needs to be completed.
      // Any stop() awaiters will be scheduled to continue after the onclose callback fires.
      _stopCompleter.complete();
    }

To:

if (_connectionState == ConnectionState.disconnecting) {
  if (!_stopCompleter.isCompleted) {
        // A call to stop() induced this call to stopConnection and needs to be completed.
        // Any stop() awaiters will be scheduled to continue after the onclose callback fires.
        _stopCompleter.complete();
  }
}

Thank you