mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-04-19 15:25:58 -04:00
fix error sending keep alive request by resetting maker after restart
This commit is contained in:
parent
30dd997810
commit
291e18f709
@ -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());
|
||||
|
@ -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,33 +1326,31 @@ 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})
|
||||
.on('data', this._onNotification);
|
||||
|
||||
// periodically send keep alive requests // TODO (woodser): better way to keep notification stream alive?
|
||||
let firstRequest = true;
|
||||
this._keepAliveLooper = new TaskLooper(async () => {
|
||||
if (firstRequest) {
|
||||
firstRequest = false;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await this._sendNotification(new NotificationMessage()
|
||||
.setType(NotificationMessage.NotificationType.KEEP_ALIVE)
|
||||
.setTimestamp(Date.now()));
|
||||
} catch (err: any) {
|
||||
HavenoUtils.log(0, "Error sending keep alive request to Haveno daemon: " + err.message);
|
||||
}
|
||||
});
|
||||
this._keepAliveLooper.start(this._keepAlivePeriodMs);
|
||||
|
||||
setTimeout(resolve, 1000); // TODO: call returns before listener registered
|
||||
|
||||
// send request to register client listener
|
||||
this._notificationStream = this._notificationsClient.registerNotificationListener(new RegisterNotificationListenerRequest(), {password: this._password})
|
||||
.on('data', this._onNotification);
|
||||
|
||||
// periodically send keep alive requests // TODO (woodser): better way to keep notification stream alive?
|
||||
let firstRequest = true;
|
||||
this._keepAliveLooper = new TaskLooper(async () => {
|
||||
if (firstRequest) {
|
||||
firstRequest = false;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await this._sendNotification(new NotificationMessage()
|
||||
.setType(NotificationMessage.NotificationType.KEEP_ALIVE)
|
||||
.setTimestamp(Date.now()));
|
||||
} catch (err: any) {
|
||||
HavenoUtils.log(0, "Error sending keep alive request to Haveno daemon " + this.getUrl() + ": " + err.message);
|
||||
}
|
||||
});
|
||||
this._keepAliveLooper.start(this._keepAlivePeriodMs);
|
||||
|
||||
await HavenoUtils.waitFor(1000); // TODO: call returns before listener registered
|
||||
} else {
|
||||
this._notificationStream!.removeListener('data', this._onNotification);
|
||||
this._keepAliveLooper.stop();
|
||||
|
@ -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); });
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user