Skip to content

Commit

Permalink
Handle slow HS response on Redaction Queue
Browse files Browse the repository at this point in the history
Retry at least once on Timeouts...
  • Loading branch information
maranda committed Aug 27, 2024
1 parent 48bd1ee commit 15bbb02
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 : '<no message>');
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);
}
}
}
}
Expand Down

0 comments on commit 15bbb02

Please sign in to comment.