mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-07-23 06:50:55 -04:00
fix error sending keep alive request by resetting maker after restart
This commit is contained in:
parent
30dd997810
commit
291e18f709
3 changed files with 34 additions and 26 deletions
|
@ -1255,6 +1255,7 @@ test("Can schedule offers with locked funds (CI)", async () => {
|
||||||
const user3Config = {appName: user3.getAppName()};
|
const user3Config = {appName: user3.getAppName()};
|
||||||
await releaseHavenoProcess(user3);
|
await releaseHavenoProcess(user3);
|
||||||
user3 = await initHaveno(user3Config);
|
user3 = await initHaveno(user3Config);
|
||||||
|
ctx.maker = user3;
|
||||||
|
|
||||||
// has offer
|
// has offer
|
||||||
offer = await user3.getMyOffer(offer.getId());
|
offer = await user3.getMyOffer(offer.getId());
|
||||||
|
|
|
@ -79,7 +79,7 @@ export default class HavenoClient {
|
||||||
* @param {string[]} cmd - command to start the process
|
* @param {string[]} cmd - command to start the process
|
||||||
* @param {string} url - Haveno daemon url (must proxy to api port)
|
* @param {string} url - Haveno daemon url (must proxy to api port)
|
||||||
* @param {boolean} enableLogging - specifies if logging is enabled or disabled at log level 3
|
* @param {boolean} enableLogging - specifies if logging is enabled or disabled at log level 3
|
||||||
* @return {haveno} a client connected to the newly started Haveno process
|
* @return {HavenoClient} a client connected to the newly started Haveno process
|
||||||
*/
|
*/
|
||||||
static async startProcess(havenoPath: string, cmd: string[], url: string, enableLogging: boolean): Promise<HavenoClient> {
|
static async startProcess(havenoPath: string, cmd: string[], url: string, enableLogging: boolean): Promise<HavenoClient> {
|
||||||
try {
|
try {
|
||||||
|
@ -1326,9 +1326,8 @@ export default class HavenoClient {
|
||||||
async _updateNotificationListenerRegistration(): Promise<void> {
|
async _updateNotificationListenerRegistration(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const listening = this._notificationListeners.length > 0;
|
const listening = this._notificationListeners.length > 0;
|
||||||
if (listening && this._notificationStream || !listening && !this._notificationStream) return; // no difference
|
if ((listening && this._notificationStream) || (!listening && !this._notificationStream)) return; // no difference
|
||||||
if (listening) {
|
if (listening) {
|
||||||
await new Promise<void>((resolve) => {
|
|
||||||
|
|
||||||
// send request to register client listener
|
// send request to register client listener
|
||||||
this._notificationStream = this._notificationsClient.registerNotificationListener(new RegisterNotificationListenerRequest(), {password: this._password})
|
this._notificationStream = this._notificationsClient.registerNotificationListener(new RegisterNotificationListenerRequest(), {password: this._password})
|
||||||
|
@ -1346,13 +1345,12 @@ export default class HavenoClient {
|
||||||
.setType(NotificationMessage.NotificationType.KEEP_ALIVE)
|
.setType(NotificationMessage.NotificationType.KEEP_ALIVE)
|
||||||
.setTimestamp(Date.now()));
|
.setTimestamp(Date.now()));
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
HavenoUtils.log(0, "Error sending keep alive request to Haveno daemon: " + err.message);
|
HavenoUtils.log(0, "Error sending keep alive request to Haveno daemon " + this.getUrl() + ": " + err.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this._keepAliveLooper.start(this._keepAlivePeriodMs);
|
this._keepAliveLooper.start(this._keepAlivePeriodMs);
|
||||||
|
|
||||||
setTimeout(resolve, 1000); // TODO: call returns before listener registered
|
await HavenoUtils.waitFor(1000); // TODO: call returns before listener registered
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
this._notificationStream!.removeListener('data', this._onNotification);
|
this._notificationStream!.removeListener('data', this._onNotification);
|
||||||
this._keepAliveLooper.stop();
|
this._keepAliveLooper.stop();
|
||||||
|
|
|
@ -130,4 +130,13 @@ export default class HavenoUtils {
|
||||||
}
|
}
|
||||||
throw new Error("PaymentAccountForm does not have field " + fieldId);
|
throw new Error("PaymentAccountForm does not have field " + fieldId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wait for the duration.
|
||||||
|
*
|
||||||
|
* @param {number} durationMs - the duration to wait for in milliseconds
|
||||||
|
*/
|
||||||
|
static async waitFor(durationMs: number) {
|
||||||
|
return new Promise(function(resolve) { setTimeout(resolve, durationMs); });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue