From 15bbb02f77412253b002d9f7ea0bc2ddad2e7872 Mon Sep 17 00:00:00 2001 From: Marco Cirillo Date: Tue, 27 Aug 2024 10:39:39 +0200 Subject: [PATCH] Handle slow HS response on Redaction Queue Retry at least once on Timeouts... --- src/utils.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index d0a63991..75f667ed 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -98,7 +98,27 @@ export async function redactUserMessagesIn(client: MatrixSendClient, managementR } }); } catch (error) { - await managementRoom.logMessage(LogLevel.DEBUG, "utils#redactUserMessagesIn", `Caught an error while trying to redact messages for ${userIdOrGlob} in ${targetRoomId}: ${error}`, targetRoomId); + const message = error.errorMessage || error.message || (error.body ? error.body.error : ''); + if (message == "Error: ESOCKETTIMEDOUT") { + // retry once + try { + await managementRoom.logMessage(LogLevel.DEBUG, "utils#redactUserMessagesIn", `Retrying to redact messages for ${userIdOrGlob} in ${targetRoomId} due to a timeout while fetching or redacting messages`, targetRoomId); + await getMessagesByUserIn(client, userIdOrGlob, targetRoomId, limit, async (eventsToRedact) => { + for (const victimEvent of eventsToRedact) { + await managementRoom.logMessage(LogLevel.DEBUG, "utils#redactUserMessagesIn", `Redacting ${victimEvent['event_id']} in ${targetRoomId}`, targetRoomId); + if (!noop) { + await client.redactEvent(targetRoomId, victimEvent['event_id']); + } else { + await managementRoom.logMessage(LogLevel.WARN, "utils#redactUserMessagesIn", `Retried to redact ${victimEvent['event_id']} in ${targetRoomId} but Mjolnir is running in no-op mode`, targetRoomId); + } + } + }); + } catch (error) { + await managementRoom.logMessage(LogLevel.DEBUG, "utils#redactUserMessagesIn", `Caught an error while re-trying to redact messages for ${userIdOrGlob} in ${targetRoomId}: ${error}`, targetRoomId); + } + } else { + await managementRoom.logMessage(LogLevel.DEBUG, "utils#redactUserMessagesIn", `Caught an error while trying to redact messages for ${userIdOrGlob} in ${targetRoomId}: ${error}`, targetRoomId); + } } } }