Skip to content

Commit ee76fbb

Browse files
Merge branch 'main' into 198-download-request-does-not-retry-on-failure-during-download
2 parents 08c6678 + 557a5e1 commit ee76fbb

File tree

1 file changed

+28
-34
lines changed

1 file changed

+28
-34
lines changed

src/libraries/Executor.ts

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { lockFile, waitForLock } from "./FileLock";
1111
import { onExit } from "signal-exit";
1212
import { randomUUID } from "crypto";
1313
import { getInternalEnvVariable } from "../constants";
14+
import etcOSRelease from "./LinuxOSRelease";
1415

1516
class Executor {
1617
logger: Logger;
@@ -136,7 +137,9 @@ class Executor {
136137
if (portIssue || xPortIssue) {
137138
this.logger.log('Error log when exiting for port in use error:', errorLog)
138139
try {
140+
this.logger.log('Deleting database path after port issue...')
139141
await fsPromises.rm(dbPath, {recursive: true, force: true, maxRetries: 50, retryDelay: 100})
142+
this.logger.log('Successfully deleted database after port issue.')
140143
} catch (e) {
141144
this.logger.error(e)
142145
return reject(`MySQL failed to listen on a certain port. To restart MySQL with a different port, the database directory needed to be deleted. An error occurred while deleting the database directory. Aborting. The error was: ${e}`)
@@ -296,28 +299,16 @@ class Executor {
296299
})
297300
}
298301

299-
async #setupDataDirectories(options: InternalServerOptions, binaryFilepath: string, datadir: string, retry: boolean): Promise<void> {
302+
async #setupDataDirectories(options: InternalServerOptions, binary: DownloadedMySQLVersion, datadir: string, retry: boolean): Promise<void> {
303+
const binaryFilepath = binary.path
300304
this.logger.log('Created data directory for database at:', datadir)
301305
await fsPromises.mkdir(datadir, {recursive: true})
302306

303-
let stderr: string;
307+
const {error, stderr} = await this.#executeFile(binaryFilepath, ['--no-defaults', `--datadir=${datadir}`, '--initialize-insecure'])
304308

305-
if (binaryFilepath === 'mysqld') {
306-
const {error, stderr: output} = await this.#executeFile('mysqld', ['--no-defaults', `--datadir=${datadir}`, '--initialize-insecure'])
307-
stderr = output
308-
if (error) {
309-
this.logger.error('An error occurred while initializing database with system-installed MySQL:', error)
310-
throw 'An error occurred while initializing database with system-installed MySQL. Please check the console for more information.'
311-
}
312-
} else {
313-
let result: {stderr: string, stdout: string};
314-
try {
315-
result = await this.#executeFile(`${binaryFilepath}`, [`--no-defaults`, `--datadir=${datadir}`, `--initialize-insecure`])
316-
} catch (e) {
317-
this.logger.error('Error occurred from executeFile:', e)
318-
throw e
319-
}
320-
stderr = result?.stderr
309+
if (binary.installedOnSystem && error) {
310+
this.logger.error('An error occurred while initializing database with the system-installed MySQL binary:', error)
311+
throw `An error occurred while initializing the MySQL database: ${error}`
321312
}
322313

323314
if (stderr && !stderr.includes('is created with an empty password')) {
@@ -327,26 +318,29 @@ class Executor {
327318
}
328319

329320
if (process.platform === 'linux' && stderr.includes('libaio.so')) {
330-
if (binaryFilepath === 'mysqld') {
331-
throw 'libaio could not be found while running system-installed MySQL. libaio must be installed on this system for MySQL to run. To learn more, please check out https://dev.mysql.com/doc/refman/en/binary-installation.html'
332-
}
333-
334321
if (retry === false) {
335322
this.logger.error('An error occurred while initializing database:', stderr)
336323
throw 'Tried to copy libaio into lib folder and MySQL is still failing to initialize. Please check the console for more information.'
337324
}
338325

339-
if (binaryFilepath.slice(-16) === 'mysql/bin/mysqld') {
326+
if (binary.installedOnSystem) {
327+
throw 'libaio could not be found while running system-installed MySQL. libaio must be installed on this system for MySQL to run. To learn more, please check out https://dev.mysql.com/doc/refman/en/binary-installation.html'
328+
}
329+
330+
// If the below code is running, the version of MySQL that is trying to be executed was downloaded from the CDN by this package and libaio has not yet been attempted to be copied
331+
332+
if (etcOSRelease.NAME === 'Ubuntu' && etcOSRelease.VERSION_ID >= '24.04') {
340333
const {error: lderror, stdout, stderr: ldstderr} = await this.#executeFile('ldconfig', ['-p'])
341334
if (lderror || ldstderr) {
342335
this.logger.error('The following libaio error occurred:', stderr)
343336
this.logger.error('After the libaio error, an ldconfig error occurred:', lderror || ldstderr)
344-
throw 'The ldconfig command failed to run. This command was ran to find libaio because libaio could not be found on the system. libaio is needed for MySQL to run. Do you have ldconfig and libaio installed? Learn more about libaio at Learn more at https://dev.mysql.com/doc/refman/en/binary-installation.html'
337+
throw 'The ldconfig command failed to run. This command was ran to find libaio1t64 because libaio1t64 could not be found on the system. libaio1t64 is needed for MySQL to run. Do you have ldconfig and libaio1t64 installed? Learn more at https://dev.mysql.com/doc/refman/en/binary-installation.html'
345338
}
346339
const libaioFound = stdout.split('\n').filter(lib => lib.includes('libaio.so.1t64'))
347340
if (!libaioFound.length) {
348341
this.logger.error('Error from launching MySQL:', stderr)
349-
throw 'An error occurred while launching MySQL. The most likely cause is that libaio1 and libaio1t64 could not be found. Either libaio1 or libaio1t64 must be installed on this system for MySQL to run. To learn more, please check out https://dev.mysql.com/doc/refman/en/binary-installation.html. Check error in console for more information.'
342+
this.logger.error('Could not find libaio1t64 in this list:', libaioFound)
343+
throw 'An error occurred while launching MySQL because libaio1t64 is not installed on your system. Please install libaio1t64 and then use mysql-memory-server again. To learn more, please check out https://dev.mysql.com/doc/refman/en/binary-installation.html. Check error in console for more information.'
350344
}
351345
const libaioEntry = libaioFound[0]
352346
const libaioPathIndex = libaioEntry.indexOf('=>')
@@ -417,17 +411,17 @@ class Executor {
417411
if (copyError) {
418412
throw 'An error occurred while copying libaio1t64 to the MySQL lib folder. Please check the console for more details.'
419413
}
420-
421-
//Retry setting up directory now that libaio has been copied
422-
this.logger.log('Retrying directory setup')
423-
await fsPromises.rm(datadir, {recursive: true, force: true, maxRetries: 50, retryDelay: 100})
424-
await this.#setupDataDirectories(options, binaryFilepath, datadir, false)
425-
return
426414
}
427415
}
428-
} else {
429-
throw 'Cannot recognize file structure for the MySQL binary folder. This was caused by not being able to find libaio. Try installing libaio. Learn more at https://dev.mysql.com/doc/refman/en/binary-installation.html'
416+
417+
//Retry setting up directory now that libaio has been copied
418+
this.logger.log('Retrying directory setup')
419+
await fsPromises.rm(datadir, {recursive: true, force: true, maxRetries: 50, retryDelay: 100})
420+
await this.#setupDataDirectories(options, binary, datadir, false)
421+
return
430422
}
423+
424+
throw 'You do not have libaio1 installed. Please install the libaio1 package for the downloaded MySQL binary to run. Learn more here: https://dev.mysql.com/doc/refman/en/binary-installation.html'
431425
}
432426
throw stderr
433427
}
@@ -490,7 +484,7 @@ class Executor {
490484
const datadir = normalizePath(`${this.databasePath}/data`)
491485

492486
do {
493-
await this.#setupDataDirectories(options, installedMySQLBinary.path, datadir, true);
487+
await this.#setupDataDirectories(options, installedMySQLBinary, datadir, true);
494488
this.logger.log('Setting up directories was successful')
495489

496490
const port = options.port || GenerateRandomPort()

0 commit comments

Comments
 (0)