in lib/src/connection.dart [403:439]
Future _terminate(int errorCode,
{bool causedByTransportError = false, String? message}) {
// TODO: When do we complete here?
if (_state.state != ConnectionState.Terminated) {
_state.state = ConnectionState.Terminated;
var cancelFuture = Future.sync(_frameReaderSubscription.cancel);
if (!causedByTransportError) {
_outgoingQueue.enqueueMessage(GoawayMessage(
_streams.highestPeerInitiatedStream,
errorCode,
message != null ? utf8.encode(message) : []));
}
var closeFuture = _frameWriter.close().catchError((e, s) {
// We ignore any errors after writing to [GoawayFrame]
});
// Close all lower level handlers with an error message.
// (e.g. if there is a pending connection.ping(), it's returned
// Future will complete with this error).
var exception = TransportConnectionException(
errorCode, 'Connection is being forcefully terminated.');
// Close all streams & stream queues
_streams.terminate(exception);
// Close the connection queues
_incomingQueue.terminate(exception);
_outgoingQueue.terminate(exception);
_pingHandler.terminate(exception);
_settingsHandler.terminate(exception);
return Future.wait([cancelFuture, closeFuture]).catchError((_) {});
}
return Future.value();
}