mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 07:56:16 -04:00
SocketIORouter: Don't crash if message handler throws
This commit is contained in:
parent
320e5c1109
commit
9f9adb369b
2 changed files with 25 additions and 2 deletions
|
@ -78,7 +78,11 @@ exports.setSocketIO = (_io) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.debug(`from ${socket.id}: ${JSON.stringify(message)}`);
|
logger.debug(`from ${socket.id}: ${JSON.stringify(message)}`);
|
||||||
await components[message.component].handleMessage(socket, message);
|
try {
|
||||||
|
await components[message.component].handleMessage(socket, message);
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(`Error while handling message from ${socket.id}: ${err.stack || err}`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('disconnect', (reason) => {
|
socket.on('disconnect', (reason) => {
|
||||||
|
|
|
@ -460,7 +460,7 @@ describe(__filename, function () {
|
||||||
await disconnected;
|
await disconnected;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handleMessage', async function () {
|
it('handleMessage (success)', async function () {
|
||||||
let serverSocket;
|
let serverSocket;
|
||||||
const want = {
|
const want = {
|
||||||
component: this.test.fullTitle(),
|
component: this.test.fullTitle(),
|
||||||
|
@ -480,5 +480,24 @@ describe(__filename, function () {
|
||||||
socket.send(want);
|
socket.send(want);
|
||||||
assert.deepEqual(await got, want);
|
assert.deepEqual(await got, want);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('handleMessage (error)', async function () {
|
||||||
|
let receive;
|
||||||
|
const received = new Promise((resolve) => receive = resolve);
|
||||||
|
socketIoRouter.addComponent(this.test.fullTitle(), new class extends Module {
|
||||||
|
handleMessage(socket, message) {
|
||||||
|
if (message.throw) throw new Error('injected');
|
||||||
|
receive();
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
socket = await connect();
|
||||||
|
const tx = (msg = {}) => {
|
||||||
|
msg = Object.assign({component: this.test.fullTitle(), protocolVersion: 2}, msg);
|
||||||
|
socket.send(msg);
|
||||||
|
};
|
||||||
|
tx({throw: true});
|
||||||
|
tx();
|
||||||
|
await received;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue