Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/logical-replication-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,14 @@ export class LogicalReplicationService extends EventEmitter2 implements LogicalR
this._messageQueue = [];
this._processing = false;

// End the client before removing listeners so the subscribe() promise
// can resolve/reject properly when the connection closes.
await this._client?.end();

this._connection?.removeAllListeners();
this._connection = null;

this._client?.removeAllListeners();
await this._client?.end();
this._client = null;

this.checkStandbyStatus(false);
Expand Down Expand Up @@ -170,7 +173,10 @@ export class LogicalReplicationService extends EventEmitter2 implements LogicalR
this._lastLsn = lsn;
});

return plugin.start(client, slotName, this._lastLsn || '0/00000000');
return plugin.start(client, slotName, this._lastLsn || '0/00000000').catch(e => {
if (!this._stop || !/Connection\s+terminated/i.test(e?.toString()))
throw e;
});
} catch (e) {
await this.stop();
this.emit('error', e);
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
"types": ["jest", "node"], /* Specify type package names to be included without being referenced in a source file. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
// "resolveJsonModule": true, /* Enable importing .json files. */
Expand Down
Loading