mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 21:19:13 +00:00
Fix crash from exceptions in handlers (#771)
* Fix crash from exceptions in handlers * Fix withScope usage * Add changelog
This commit is contained in:
parent
6ca2b51893
commit
96c398ce74
1
changelog.d/771.bugfix
Normal file
1
changelog.d/771.bugfix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Fix crash when failing to handle events, typically due to lacking permissions to send messages in a room.
|
@ -786,22 +786,24 @@ export class Bridge {
|
|||||||
this.ready = true;
|
this.ready = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleHookshotEvent<EventType, ConnType extends IConnection>(msg: MessageQueueMessageOut<EventType>, connection: ConnType, handler: (c: ConnType, data: EventType) => Promise<unknown>|unknown) {
|
private async handleHookshotEvent<EventType, ConnType extends IConnection>(msg: MessageQueueMessageOut<EventType>, connection: ConnType, handler: (c: ConnType, data: EventType) => Promise<unknown>|unknown) {
|
||||||
Sentry.withScope((scope) => {
|
try {
|
||||||
scope.setTransactionName('handleHookshotEvent');
|
await handler(connection, msg.data);
|
||||||
scope.setTags({
|
} catch (e) {
|
||||||
eventType: msg.eventName,
|
Sentry.withScope((scope) => {
|
||||||
roomId: connection.roomId,
|
scope.setTransactionName('handleHookshotEvent');
|
||||||
});
|
scope.setTags({
|
||||||
scope.setContext("connection", {
|
eventType: msg.eventName,
|
||||||
id: connection.connectionId,
|
roomId: connection.roomId,
|
||||||
});
|
});
|
||||||
new Promise(() => handler(connection, msg.data)).catch((ex) => {
|
scope.setContext("connection", {
|
||||||
Sentry.captureException(ex, scope);
|
id: connection.connectionId,
|
||||||
|
});
|
||||||
|
log.warn(`Connection ${connection.toString()} failed to handle ${msg.eventName}:`, e);
|
||||||
Metrics.connectionsEventFailed.inc({ event: msg.eventName, connectionId: connection.connectionId });
|
Metrics.connectionsEventFailed.inc({ event: msg.eventName, connectionId: connection.connectionId });
|
||||||
log.warn(`Connection ${connection.toString()} failed to handle ${msg.eventName}:`, ex);
|
Sentry.captureException(e, scope);
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async bindHandlerToQueue<EventType, ConnType extends IConnection>(event: string, connectionFetcher: (data: EventType) => ConnType[], handler: (c: ConnType, data: EventType) => Promise<unknown>|unknown) {
|
private async bindHandlerToQueue<EventType, ConnType extends IConnection>(event: string, connectionFetcher: (data: EventType) => ConnType[], handler: (c: ConnType, data: EventType) => Promise<unknown>|unknown) {
|
||||||
@ -810,8 +812,8 @@ export class Bridge {
|
|||||||
const connections = connectionFetcherBound(msg.data);
|
const connections = connectionFetcherBound(msg.data);
|
||||||
log.debug(`${event} for ${connections.map(c => c.toString()).join(', ') || '[empty]'}`);
|
log.debug(`${event} for ${connections.map(c => c.toString()).join(', ') || '[empty]'}`);
|
||||||
connections.forEach((connection) => {
|
connections.forEach((connection) => {
|
||||||
this.handleHookshotEvent(msg, connection, handler);
|
void this.handleHookshotEvent(msg, connection, handler);
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1167,7 +1169,7 @@ export class Bridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const connection of this.connectionManager.getAllConnectionsForRoom(roomId)) {
|
for (const connection of this.connectionManager.getAllConnectionsForRoom(roomId)) {
|
||||||
if (!connection.onEvent) {
|
if (!connection.onEvent) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const scope = new Sentry.Scope();
|
const scope = new Sentry.Scope();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user