From 8845c9b8d6031256cfaea749845026d5f6166ea6 Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Mon, 7 Feb 2022 14:33:41 -0800 Subject: [PATCH] fix minor issue with postgres listener dealing with connection errors and shutdown --- server.js | 3 ++- src/db/postgres/listener.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) 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. -- 2.45.2