Skip to content

Commit c061bf9

Browse files
chore: remove deleteDatabaseDirectory method in favour of fs.rm (#179)
1 parent 8eaea9a commit c061bf9

File tree

1 file changed

+3
-27
lines changed

1 file changed

+3
-27
lines changed

src/libraries/Executor.ts

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,6 @@ class Executor {
4646
return killed;
4747
}
4848

49-
async #deleteDatabaseDirectory(path: string): Promise<void> {
50-
let retries = 0;
51-
//Maximum wait of 10 seconds | 500ms * 20 retries = 10,000ms = 10 seconds
52-
const waitTime = 500;
53-
const maxRetries = 20;
54-
55-
//Since the database processes are killed instantly (SIGKILL) sometimes the database file handles may still be open
56-
//This would cause an EBUSY error. Retrying the deletions for 10 seconds should give the OS enough time to close
57-
//the file handles.
58-
while (retries <= maxRetries) {
59-
try {
60-
await fsPromises.rm(path, {recursive: true, force: true})
61-
return
62-
} catch (e) {
63-
if (retries === maxRetries) {
64-
throw e
65-
}
66-
await new Promise(resolve => setTimeout(resolve, waitTime))
67-
retries++
68-
this.logger.log('DB data directory deletion failed. Now on retry', retries)
69-
}
70-
}
71-
}
72-
7349
//Returns a path to the binary if it should be deleted
7450
//If it should not be deleted then it returns null
7551
#returnBinaryPathToDelete(binaryFilepath: string, options: InternalServerOptions): string | null {
@@ -118,7 +94,7 @@ class Executor {
11894
if (portIssue || xPortIssue) {
11995
this.logger.log('Error log when exiting for port in use error:', errorLog)
12096
try {
121-
await this.#deleteDatabaseDirectory(getInternalEnvVariable('dbPath'))
97+
await fsPromises.rm(dbPath, {recursive: true, force: true, maxRetries: 50, retryDelay: 100})
12298
} catch (e) {
12399
this.logger.error(e)
124100
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}`)
@@ -128,7 +104,7 @@ class Executor {
128104

129105
try {
130106
if (getInternalEnvVariable('deleteDBAfterStopped') === 'true') {
131-
await this.#deleteDatabaseDirectory(dbPath)
107+
await fsPromises.rm(dbPath, {recursive: true, force: true, maxRetries: 50, retryDelay: 100})
132108
}
133109
} catch (e) {
134110
this.logger.error('An error occurred while deleting database directory at path:', dbPath, '| The error was:', e)
@@ -396,7 +372,7 @@ class Executor {
396372

397373
//Retry setting up directory now that libaio has been copied
398374
this.logger.log('Retrying directory setup')
399-
await this.#deleteDatabaseDirectory(datadir)
375+
await fsPromises.rm(datadir, {recursive: true, force: true, maxRetries: 50, retryDelay: 100})
400376
await this.#setupDataDirectories(options, binaryFilepath, datadir, false)
401377
return
402378
}

0 commit comments

Comments
 (0)