fix error sending keep alive request by resetting maker after restart

This commit is contained in:
woodser 2023-02-24 10:19:26 -05:00
parent 30dd997810
commit 291e18f709
3 changed files with 34 additions and 26 deletions

View File

@ -1255,6 +1255,7 @@ test("Can schedule offers with locked funds (CI)", async () => {
const user3Config = {appName: user3.getAppName()};
await releaseHavenoProcess(user3);
user3 = await initHaveno(user3Config);
ctx.maker = user3;
// has offer
offer = await user3.getMyOffer(offer.getId());

View File

@ -79,7 +79,7 @@ export default class HavenoClient {
* @param {string[]} cmd - command to start the process
* @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
* @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> {
try {
@ -1326,9 +1326,8 @@ export default class HavenoClient {
async _updateNotificationListenerRegistration(): Promise<void> {
try {
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) {
await new Promise<void>((resolve) => {
// send request to register client listener
this._notificationStream = this._notificationsClient.registerNotificationListener(new RegisterNotificationListenerRequest(), {password: this._password})
@ -1346,13 +1345,12 @@ export default class HavenoClient {
.setType(NotificationMessage.NotificationType.KEEP_ALIVE)
.setTimestamp(Date.now()));
} 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);
setTimeout(resolve, 1000); // TODO: call returns before listener registered
});
await HavenoUtils.waitFor(1000); // TODO: call returns before listener registered
} else {
this._notificationStream!.removeListener('data', this._onNotification);
this._keepAliveLooper.stop();

View File

@ -130,4 +130,13 @@ export default class HavenoUtils {
}
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); });
}
}