Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle 'error' events from pool connection #6262

Merged
merged 1 commit into from Sep 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/driver/postgres/PostgresQueryRunner.ts
Expand Up @@ -102,10 +102,14 @@ export class PostgresQueryRunner extends BaseQueryRunner implements QueryRunner
* Releases used database connection.
* You cannot use query runner methods once its released.
*/
release(): Promise<void> {
release(err?: any): Promise<void> {
if (this.isReleased) {
return Promise.resolve();
}

this.isReleased = true;
if (this.releaseCallback)
this.releaseCallback();
this.releaseCallback(err);

const index = this.driver.connectedQueryRunners.indexOf(this);
if (index !== -1) this.driver.connectedQueryRunners.splice(index);
Expand Down Expand Up @@ -164,7 +168,13 @@ export class PostgresQueryRunner extends BaseQueryRunner implements QueryRunner
this.driver.connection.logger.logQuery(query, parameters, this);
const queryStartTime = +new Date();

const onError = (err: any) => {
this.release(err);
};
databaseConnection.once("error", onError);

databaseConnection.query(query, parameters, (err: any, result: any) => {
databaseConnection.removeListener("error", onError);

// log slow queries if maxQueryExecution time is set
const maxQueryExecutionTime = this.driver.connection.options.maxQueryExecutionTime;
Expand Down