Skip to content

Commit

Permalink
Mysql2 validate connection fix #4794 (#4812)
Browse files Browse the repository at this point in the history
(cherry picked from commit 89bd0a0)
  • Loading branch information
OlivierCavadenti committed Nov 8, 2021
1 parent 29ac476 commit 337178f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
10 changes: 3 additions & 7 deletions lib/dialects/mysql/index.js
Expand Up @@ -89,13 +89,9 @@ class Client_MySQL extends Client {
}

validateConnection(connection) {
if (
connection.state === 'connected' ||
connection.state === 'authenticated'
) {
return true;
}
return false;
return (
connection.state === 'connected' || connection.state === 'authenticated'
);
}

// Grab a connection, run the query via the MySQL streaming interface,
Expand Down
11 changes: 7 additions & 4 deletions lib/dialects/mysql2/index.js
Expand Up @@ -15,10 +15,13 @@ class Client_MySQL2 extends Client_MySQL {
return require('mysql2');
}
validateConnection(connection) {
if (connection._fatalError) {
return false;
}
return true;
return (
connection &&
!connection._fatalError &&
!connection._protocolError &&
!connection._closing &&
!connection.stream.destroyed
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/tape/pool.js
Expand Up @@ -23,7 +23,7 @@ test(`pool evicts dead resources when factory.validate rejects`, async (t) => {
},

validate: (res) => {
return res.error ? false : true;
return !res.error;
},

destroy: (res) => {
Expand Down

0 comments on commit 337178f

Please sign in to comment.