From fa5abfca92421c6f230d7ffddb0d1201a6f77b57 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Wed, 8 Dec 2021 13:00:53 +0100 Subject: [PATCH] fix: ignore 4xx errors when re-sending the to_device queue The to_device queue was introduced to ensure integrity if e.g. the server temporarily failed when attempting to send a to_device message. If, for whatever reason, the server responds with a 4xx error, though, then we want to ignore that to_device message from the queue and move on, as that means that something different was fundamentally wrong. This helps to fix the to_device queue clogging up, making clients incapable of sending to_device events anymore, should such clogging happen. --- lib/src/client.dart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index 710fcd59..1f4a2c62 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -2055,7 +2055,13 @@ class Client extends MatrixApi { (v as Map).map((k, v) => MapEntry>( k, Map.from(v))))); - await super.sendToDevice(entry.type, entry.txnId, data); + try { + await super.sendToDevice(entry.type, entry.txnId, data); + } on MatrixException catch (e) { + Logs().w( + '[To-Device] failed to to_device message from the queue to the server. Ignoring error: $e'); + Logs().w('Payload: $data'); + } await database.deleteFromToDeviceQueue(entry.id); } }