mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 15:13:21 +00:00
fix: prevent infinite loop opening pool connections in mysql
This commit is contained in:
parent
ce799d38e6
commit
92e0fee2c4
@ -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];
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user