mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-07-23 06:50:55 -04:00
fix hanging java and monero processes on 400 or 500 error
This commit is contained in:
parent
9608a4236c
commit
222fe7e528
2 changed files with 67 additions and 61 deletions
|
@ -520,7 +520,6 @@ beforeEach(async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
try {
|
|
||||||
|
|
||||||
// set log level for tests
|
// set log level for tests
|
||||||
HavenoUtils.setLogLevel(TestConfig.logLevel);
|
HavenoUtils.setLogLevel(TestConfig.logLevel);
|
||||||
|
@ -553,8 +552,9 @@ beforeAll(async () => {
|
||||||
if (settledPromise.status === "fulfilled") {
|
if (settledPromise.status === "fulfilled") {
|
||||||
startupHavenods.push((settledPromise as PromiseFulfilledResult<HavenoClient>).value);
|
startupHavenods.push((settledPromise as PromiseFulfilledResult<HavenoClient>).value);
|
||||||
startupHavenodUrls.push(startupHavenods[startupHavenods.length - 1].getUrl());
|
startupHavenodUrls.push(startupHavenods[startupHavenods.length - 1].getUrl());
|
||||||
|
} else if (!err) {
|
||||||
|
err = new Error((settledPromise as PromiseRejectedResult).reason);
|
||||||
}
|
}
|
||||||
else if (!err) err = new Error((settledPromise as PromiseRejectedResult).reason);
|
|
||||||
}
|
}
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
|
@ -575,10 +575,6 @@ beforeAll(async () => {
|
||||||
|
|
||||||
// create test data directory if it doesn't exist
|
// create test data directory if it doesn't exist
|
||||||
if (!fs.existsSync(TestConfig.testDataDir)) fs.mkdirSync(TestConfig.testDataDir);
|
if (!fs.existsSync(TestConfig.testDataDir)) fs.mkdirSync(TestConfig.testDataDir);
|
||||||
} catch (err) {
|
|
||||||
await shutDown();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
|
@ -3571,14 +3567,16 @@ async function releaseHavenoClient(client: HavenoClient, deleteProcessAppDir?: b
|
||||||
async function releaseHavenoProcess(havenod: HavenoClient, deleteAppDir?: boolean) {
|
async function releaseHavenoProcess(havenod: HavenoClient, deleteAppDir?: boolean) {
|
||||||
if (!testsOwnProcess(havenod)) throw new Error("Cannot shut down havenod process which is not owned by test");
|
if (!testsOwnProcess(havenod)) throw new Error("Cannot shut down havenod process which is not owned by test");
|
||||||
if (!moneroTs.GenUtils.arrayContains(HAVENO_CLIENTS, havenod)) throw new Error("Cannot release Haveno client which is not in list of clients");
|
if (!moneroTs.GenUtils.arrayContains(HAVENO_CLIENTS, havenod)) throw new Error("Cannot release Haveno client which is not in list of clients");
|
||||||
moneroTs.GenUtils.remove(HAVENO_CLIENTS, havenod);
|
let shutDownErr = undefined;
|
||||||
moneroTs.GenUtils.remove(HAVENO_PROCESS_PORTS, getPort(havenod.getUrl()));
|
|
||||||
try {
|
try {
|
||||||
await havenod.shutdownServer();
|
await havenod.shutdownServer();
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
assert(err.message.indexOf(OFFLINE_ERR_MSG) >= 0, "Unexpected error shutting down server: " + err.message);
|
shutDownErr = err;
|
||||||
}
|
}
|
||||||
|
if (shutDownErr) throw shutDownErr;
|
||||||
if (deleteAppDir) deleteHavenoInstance(havenod);
|
if (deleteAppDir) deleteHavenoInstance(havenod);
|
||||||
|
moneroTs.GenUtils.remove(HAVENO_CLIENTS, havenod);
|
||||||
|
moneroTs.GenUtils.remove(HAVENO_PROCESS_PORTS, getPort(havenod.getUrl()));
|
||||||
}
|
}
|
||||||
|
|
||||||
function testsOwnProcess(havenod: HavenoClient) {
|
function testsOwnProcess(havenod: HavenoClient) {
|
||||||
|
|
|
@ -1330,7 +1330,15 @@ export default class HavenoClient {
|
||||||
await this._shutdownServerClient.stop(new StopRequest(), {password: this._password}); // process receives 'exit' event
|
await this._shutdownServerClient.stop(new StopRequest(), {password: this._password}); // process receives 'exit' event
|
||||||
if (this._process) await HavenoUtils.kill(this._process);
|
if (this._process) await HavenoUtils.kill(this._process);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
throw new HavenoError(e.message, e.code);
|
console.error("Error gracefully shutting down havenod: " + e.message);
|
||||||
|
if (this._process) {
|
||||||
|
try {
|
||||||
|
await HavenoUtils.kill(this._process);
|
||||||
|
} catch (e: any) {
|
||||||
|
console.error("Error terminating havenod process: " + e.message + ". Stopping forcefully");
|
||||||
|
await HavenoUtils.kill(this._process, "SIGKILL");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue