pg-logical-replication icon indicating copy to clipboard operation
pg-logical-replication copied to clipboard

Don't use async methods in sync handlers.

Open jpdsteno opened this issue 9 months ago • 1 comments

Invoking async methods in synchronous event handlers (see example below) can lead to unhandled rejections which can trigger fatal application restarts.

        if (this.config.acknowledge.timeoutSeconds > 0 && enable)
            this.checkStandbyStatusTimer = setInterval(async () => {
                if (this._stop)
                    return;
                if (this._lastLsn &&
                    Date.now() - this.lastStandbyStatusUpdatedTime > this.config.acknowledge.timeoutSeconds * 1000)
                    await this.acknowledge(this._lastLsn);
            }, 1000); 

Any async handler should catch all exceptions or avoid async and ensure the invoked promise has a catch handler.

jpdsteno avatar Mar 03 '25 17:03 jpdsteno

@jmealo Hello. Could you submit your improvement as a PR? Thank you.

kibae avatar Oct 23 '25 01:10 kibae