fix(core): Fix reconnections not working properly

This commit is contained in:
PapaTutuWawa 2023-03-21 12:01:22 +01:00
parent 70d4d6c56f
commit 4321573dfb

View File

@ -374,8 +374,11 @@ class XmppConnection {
// Connect again // Connect again
// ignore: cascade_invocations // ignore: cascade_invocations
_log.finest('Calling connect() from _attemptReconnection'); _log.finest('Calling _connectImpl() from _attemptReconnection');
await connect(waitForConnection: true); await _connectImpl(
waitForConnection: true,
ignoreLock: true,
);
} }
/// Called when a stream ending error has occurred /// Called when a stream ending error has occurred
@ -1133,25 +1136,36 @@ class XmppConnection {
); );
} }
/// The private implementation for [XmppConnection.connect]. The parameters have
/// the same meaning as with [XmppConnection.connect].
///
/// [ignoreLock] is a flag that, if true, causes the method to not try to aquire
/// a connection lock. This is useful when we already aquired the connection lock,
/// for example, in _attemptReconnection.
Future<Result<bool, XmppError>> _connectImpl({ Future<Result<bool, XmppError>> _connectImpl({
String? lastResource, String? lastResource,
bool waitForConnection = false, bool waitForConnection = false,
bool shouldReconnect = true, bool shouldReconnect = true,
bool waitUntilLogin = false, bool waitUntilLogin = false,
bool enableReconnectOnSuccess = true, bool enableReconnectOnSuccess = true,
bool ignoreLock = false,
}) async { }) async {
if (await _testAndSetIsConnectionRunning()) { if (!ignoreLock) {
_log.fine( if (await _testAndSetIsConnectionRunning()) {
'Cancelling this connection attempt as one appears to be already running.', _log.fine(
); 'Cancelling this connection attempt as one appears to be already running.',
return Future.value( );
Result( return Future.value(
ConnectionAlreadyRunningError(), Result(
), ConnectionAlreadyRunningError(),
); ),
} );
}
await _resetIsConnectionRunning(); await _resetIsConnectionRunning();
} else {
_log.fine('Ignoring connection lock as ignoreLock = true');
}
if (waitUntilLogin) { if (waitUntilLogin) {
_log.finest('Setting up completer for awaiting completed login'); _log.finest('Setting up completer for awaiting completed login');