fix: prevent infinite loop opening pool connections in mysql

This commit is contained in:
Ben Irvin 2024-02-21 11:54:47 +01:00 committed by GitHub
parent ce799d38e6
commit 92e0fee2c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View File

@ -17,11 +17,13 @@ export default class MysqlDatabaseInspector {
this.db = db;
}
async getInformation(): Promise<Information> {
async getInformation(nativeConnection?: unknown): Promise<Information> {
let database: Information['database'];
let versionNumber: Information['version'];
try {
const [results] = await this.db.connection.raw(SQL_QUERIES.VERSION);
const [results] = await this.db.connection
.raw(SQL_QUERIES.VERSION)
.connection(nativeConnection);
const versionSplit = results[0].version.split('-');
const databaseName = versionSplit[1];
versionNumber = versionSplit[0];

View File

@ -62,8 +62,13 @@ export default class MysqlDialect extends Dialect {
}
// We only need to get info on the first connection in the pool
/**
* Note: There is a race condition here where if two connections are opened at the same time, both will retrieve
* db info, but it doesn't cause issues, it's just one wasted query one time, so we can safely leave it to avoid
* adding extra complexity
* */
if (!this.info) {
this.info = await this.databaseInspector.getInformation();
this.info = await this.databaseInspector.getInformation(nativeConnection);
}
}