Handle WS exceptions on server side

This commit is contained in:
Tony Garnock-Jones 2019-05-28 16:54:46 +01:00
parent a0efda90f9
commit 08a8d51de6
1 changed files with 12 additions and 2 deletions

View File

@ -209,10 +209,20 @@ function _server(host, port, httpsOptions) {
react {
const facet = currentFacet();
const guard = (f) => {
try {
f()
} catch (e) {
// Swallow e, which will be some kind of websocket-related exception.
console.debug('WebSocket exception in actor '+facet.actor.toString(), e);
facet.stop();
}
};
let id = genUuid('_wsRequest');
assert WebSocket(id, server, pieces, url.query);
on stop ws.close();
on stop guard(() => ws.close());
ws.on('close', Dataspace.wrapExternal(() => {
facet.stop();
@ -225,7 +235,7 @@ function _server(host, port, httpsOptions) {
}
on message DataOut(id, $message) {
ws.send(Bytes.toIO(message));
guard(() => ws.send(Bytes.toIO(message)));
}
stop on retracted Observe(WebSocket(_, server, pathPattern, _));