Improve WebSocketServer Error Handling (#6230)
* Improve WebSocketServer Error Handling Closes: https://github.com/parse-community/parse-server/issues/6173 Prevents an unhandled server rejection. Includes an example for LiveQuery test and closing the proper connections. Improve live query monitoring * fix tests
This commit is contained in:
@@ -13,10 +13,12 @@ export class WSAdapter extends WSSAdapter {
|
||||
|
||||
onListen() {}
|
||||
onConnection(ws) {}
|
||||
onError(error) {}
|
||||
start() {
|
||||
const wss = new WebSocketServer({ server: this.options.server });
|
||||
wss.on('listening', this.onListen);
|
||||
wss.on('connection', this.onConnection);
|
||||
wss.on('error', this.onError);
|
||||
}
|
||||
close() {}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// Adapter classes must implement the following functions:
|
||||
// * onListen()
|
||||
// * onConnection(ws)
|
||||
// * onError(error)
|
||||
// * start()
|
||||
// * close()
|
||||
//
|
||||
@@ -22,6 +23,7 @@ export class WSSAdapter {
|
||||
constructor(options) {
|
||||
this.onListen = () => {};
|
||||
this.onConnection = () => {};
|
||||
this.onError = () => {};
|
||||
}
|
||||
|
||||
// /**
|
||||
@@ -36,6 +38,13 @@ export class WSSAdapter {
|
||||
// */
|
||||
// onConnection(ws) {}
|
||||
|
||||
// /**
|
||||
// * Emitted when error event is called.
|
||||
// *
|
||||
// * @param {Error} error - WebSocketServer error
|
||||
// */
|
||||
// onError(error) {}
|
||||
|
||||
/**
|
||||
* Initialize Connection.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user