fix: attach error handler early enough (#5552)

This commit is contained in:
Luke Stevens 2023-07-04 12:53:19 -07:00 committed by GitHub
parent 2a6c20f27c
commit e7dc724fcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -80,6 +80,14 @@ class Client_PG extends Client {
_acquireOnlyConnection() {
const connection = new this.driver.Client(this.connectionSettings);
connection.on('error', (err) => {
connection.__knex__disposed = err;
});
connection.on('end', (err) => {
connection.__knex__disposed = err || 'Connection ended unexpectedly';
});
return connection.connect().then(() => connection);
}
@ -90,14 +98,6 @@ class Client_PG extends Client {
return this._acquireOnlyConnection()
.then(function (connection) {
connection.on('error', (err) => {
connection.__knex__disposed = err;
});
connection.on('end', (err) => {
connection.__knex__disposed = err || 'Connection ended unexpectedly';
});
if (!client.version) {
return client.checkVersion(connection).then(function (version) {
client.version = version;