diff --git a/src/bot.ts b/src/bot.ts index 13b0ecf9e82e0019946d16a9b3598a191e9f4451..5c630fda77403a74a483c30e09a374865a7afe85 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -465,8 +465,11 @@ export class DiscordBot { opts.embed = embed; msg = await chan.send("", opts); } - await this.StoreMessagesSent(msg, chan, event); - this.unlockChannel(chan); + // Don't block on this. + this.StoreMessagesSent(msg, chan, event).then(() => { + this.unlockChannel(chan); + }); + } catch (err) { log.error("Couldn't send message. ", err); } diff --git a/src/matrixeventprocessor.ts b/src/matrixeventprocessor.ts index 955ec8a4e1674224753aac0ba664ac10a0ff7b01..3de6de44f0dab36967cc271b0a25e0fc69e4b332 100644 --- a/src/matrixeventprocessor.ts +++ b/src/matrixeventprocessor.ts @@ -29,6 +29,7 @@ import { MatrixCommandHandler } from "./matrixcommandhandler"; import { Log } from "./log"; import { TimedCache } from "./structures/timedcache"; +import { MetricPeg } from "./metrics"; const log = new Log("MatrixEventProcessor"); const MaxFileSize = 8000000; @@ -80,6 +81,7 @@ export class MatrixEventProcessor { const event = request.getData() as IMatrixEvent; if (event.unsigned.age > AGE_LIMIT) { log.warn(`Skipping event due to age ${event.unsigned.age} > ${AGE_LIMIT}`); + MetricPeg.get.requestOutcome(event.event_id, false, "dropped"); return; } if ( @@ -120,17 +122,15 @@ export class MatrixEventProcessor { event.content!.body!.startsWith("!discord"); if (isBotCommand) { await this.mxCommandHandler.Process(event, context); - return; } else if (context.rooms.remote) { const srvChanPair = context.rooms.remote.roomId.substr("_discord".length).split("_", ROOM_NAME_PARTS); try { await this.ProcessMsgEvent(event, srvChanPair[0], srvChanPair[1]); - return; } catch (err) { log.warn("There was an error sending a matrix event", err); - return; } } + return; } else if (event.type === "m.room.encryption" && context.rooms.remote) { try { await this.HandleEncryptionWarning(event.room_id); @@ -138,10 +138,9 @@ export class MatrixEventProcessor { } catch (err) { throw new Error(`Failed to handle encrypted room, ${err}`); } - } else { - log.verbose("Got non m.room.message event"); } log.verbose("Event not processed by bridge"); + MetricPeg.get.requestOutcome(event.event_id, false, "dropped"); } public async HandleEncryptionWarning(roomId: string): Promise<void> { @@ -168,7 +167,6 @@ export class MatrixEventProcessor { log.verbose(`Looking up ${guildId}_${channelId}`); const roomLookup = await this.discord.LookupRoom(guildId, channelId, event.sender); const chan = roomLookup.channel; - const botUser = roomLookup.botUser; const embedSet = await this.EventToEmbed(event, chan); const opts: Discord.MessageOptions = {}; @@ -180,7 +178,10 @@ export class MatrixEventProcessor { } await this.discord.send(embedSet, opts, roomLookup, event); - await this.sendReadReceipt(event); + // Don't await this. + this.sendReadReceipt(event).catch((ex) => { + log.verbose("Failed to send read reciept for ", event.event_id, ex); + }); } public async ProcessStateEvent(event: IMatrixEvent) { diff --git a/src/metrics.ts b/src/metrics.ts index 698c0daf645d88173f8bba3a21cf9cd61d05bfbd..b4879dfe7b2cdccf94bd0821b5a3589abc92740f 100644 --- a/src/metrics.ts +++ b/src/metrics.ts @@ -117,11 +117,10 @@ export class PrometheusBridgeMetrics implements IBridgeMetrics { public requestOutcome(id: string, isRemote: boolean, outcome: string) { const startTime = this.requestsInFlight.get(id); - this.requestsInFlight.delete(id); if (!startTime) { - log.verbose(`Got "requestOutcome" for ${id}, but this request was never started`); return; } + this.requestsInFlight.delete(id); const duration = Date.now() - startTime; (isRemote ? this.remoteRequest : this.matrixRequest).observe({outcome}, duration / 1000); }