Skip to content

Don't use async methods in sync handlers. #62

@jpdsteno

Description

@jpdsteno

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions