From: Justin Wind Date: Mon, 7 Feb 2022 22:33:41 +0000 (-0800) Subject: fix minor issue with postgres listener dealing with connection errors and shutdown X-Git-Tag: v1.3.5^2~7 X-Git-Url: http://git.squeep.com/?p=websub-hub;a=commitdiff_plain;h=8845c9b8d6031256cfaea749845026d5f6166ea6 fix minor issue with postgres listener dealing with connection errors and shutdown --- diff --git a/server.js b/server.js index cef54a9..49ce8f6 100644 --- a/server.js +++ b/server.js @@ -26,12 +26,13 @@ const ADDR = process.env.LISTEN_ADDR || '127.0.0.1'; service.dispatch(req, res); }).listen(PORT, ADDR, (err) => { if (err) { - logger.error(_scope, 'error starting server', err); + logger.error(_scope, 'error creating server', err); throw err; } logger.info(_scope, 'server started', { version, listenAddress: ADDR, listenPort: PORT }); }); } catch (e) { (logger || console).error(_scope, 'error starting server', e); + db && db.listener && await db.listener.stop(); } })(); \ No newline at end of file diff --git a/src/db/postgres/listener.js b/src/db/postgres/listener.js index 6ad387a..4baf5d0 100644 --- a/src/db/postgres/listener.js +++ b/src/db/postgres/listener.js @@ -54,7 +54,7 @@ class PostgresListener { delete this.reconnectPending; } if (this.connection) { - this.connection.client.removeListener(this.notificationEventName, this.onNotificationBound); + this.connection.client.removeListener(this.notificationEventName, this._onNotificationBound); this.connection.done(); this.connection = null; await this.options.connectionLostCallback(); @@ -106,7 +106,7 @@ class PostgresListener { this.logger.error(_scope, 'listener connection lost', { error, event }); this.connection = null; try { - event.client.removeListener(this.notificationEventName, this.onNotificationBound); + event.client.removeListener(this.notificationEventName, this._onNotificationBound); } catch (e) { this.logger.error(_scope, 'failed to remove listener', { error: e }); // That's okay, it was probably just gone anyhow.