From 41b789fa28d4b4aa2cf642197a08a07a967f8b6b Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Fri, 29 Sep 2023 20:50:03 +0200 Subject: [PATCH] feat(core): Stop an exception in a handler to deadlock the connection --- packages/moxxmpp/CHANGELOG.md | 3 +++ packages/moxxmpp/lib/src/connection.dart | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/moxxmpp/CHANGELOG.md b/packages/moxxmpp/CHANGELOG.md index a8c57f6..ee3c3d7 100644 --- a/packages/moxxmpp/CHANGELOG.md +++ b/packages/moxxmpp/CHANGELOG.md @@ -23,6 +23,9 @@ - *BREAKING*: `UserAvatarManager`'s `getAvatarId` with `getLatestMetadata`. - The `PubSubManager` now supports PubSub's `max_items` in `getItems`. - *BREAKING*: `vCardManager`'s `VCardAvatarUpdatedEvent` no longer automatically requests the newest VCard avatar. +- *BREAKING*: `XmppConnection` now tries to ensure that incoming data is processed in-order. The only exception are awaited stanzas as they are allowed to bypass the queue. +- *BREAKING*: If a stanza handler causes an exception, the handler is simply skipped while processing. +- Add better logging around what stanza handler is running and if they end processing early. ## 0.3.1 diff --git a/packages/moxxmpp/lib/src/connection.dart b/packages/moxxmpp/lib/src/connection.dart index 1cffafe..bc8466d 100644 --- a/packages/moxxmpp/lib/src/connection.dart +++ b/packages/moxxmpp/lib/src/connection.dart @@ -685,7 +685,13 @@ class XmppConnection { _log.finest( 'Running handler for ${stanza.tag} (${stanza.attributes["id"]}) of $managerName', ); - state = await handler.callback(state.stanza, state); + try { + state = await handler.callback(state.stanza, state); + } catch (ex) { + _log.severe( + 'Handler from $managerName for ${stanza.tag} (${stanza.attributes["id"]}) failed with "$ex"', + ); + } if (state.done || state.cancel) { _log.finest( 'Processing ended early for ${stanza.tag} (${stanza.attributes["id"]}) by $managerName',