@oyasmi/pipiclaw 0.6.7-beta.2 → 0.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -80,6 +80,8 @@ export declare class DingTalkBot {
|
|
|
80
80
|
private activeMessageProcessing;
|
|
81
81
|
private keepAliveTimer;
|
|
82
82
|
private reconnectTimer;
|
|
83
|
+
private reconnectDelayTimer;
|
|
84
|
+
private reconnectDelayResolve;
|
|
83
85
|
private isReconnecting;
|
|
84
86
|
private isStopped;
|
|
85
87
|
private reconnectAttempts;
|
|
@@ -102,6 +104,7 @@ export declare class DingTalkBot {
|
|
|
102
104
|
private setTrackedInterval;
|
|
103
105
|
private clearKeepAliveTimer;
|
|
104
106
|
private clearReconnectTimer;
|
|
107
|
+
private clearReconnectDelay;
|
|
105
108
|
private clearAllTimers;
|
|
106
109
|
private sleep;
|
|
107
110
|
private waitForDelay;
|
package/dist/runtime/dingtalk.js
CHANGED
|
@@ -124,6 +124,12 @@ export class DingTalkBot {
|
|
|
124
124
|
this.activeMessageProcessing = false;
|
|
125
125
|
this.keepAliveTimer = null;
|
|
126
126
|
this.reconnectTimer = null;
|
|
127
|
+
// Dedicated timer for the in-flight backoff sleep inside doReconnect, kept
|
|
128
|
+
// separate from reconnectTimer so an external scheduleReconnect() (e.g. a
|
|
129
|
+
// WebSocket close event) can never clear the sleep out from under an active
|
|
130
|
+
// attempt and leave isReconnecting stuck true forever.
|
|
131
|
+
this.reconnectDelayTimer = null;
|
|
132
|
+
this.reconnectDelayResolve = null;
|
|
127
133
|
this.isReconnecting = false;
|
|
128
134
|
this.isStopped = false;
|
|
129
135
|
this.reconnectAttempts = 0;
|
|
@@ -202,9 +208,24 @@ export class DingTalkBot {
|
|
|
202
208
|
this.reconnectTimer = null;
|
|
203
209
|
}
|
|
204
210
|
}
|
|
211
|
+
// Cancel the backoff sleep and resolve its pending promise so the awaiting
|
|
212
|
+
// doReconnect unblocks (and then bails on the isStopped/!client re-check)
|
|
213
|
+
// instead of hanging forever.
|
|
214
|
+
clearReconnectDelay() {
|
|
215
|
+
if (this.reconnectDelayTimer) {
|
|
216
|
+
clearTimeout(this.reconnectDelayTimer);
|
|
217
|
+
this.reconnectDelayTimer = null;
|
|
218
|
+
}
|
|
219
|
+
if (this.reconnectDelayResolve) {
|
|
220
|
+
const resolve = this.reconnectDelayResolve;
|
|
221
|
+
this.reconnectDelayResolve = null;
|
|
222
|
+
resolve();
|
|
223
|
+
}
|
|
224
|
+
}
|
|
205
225
|
clearAllTimers() {
|
|
206
226
|
this.clearKeepAliveTimer();
|
|
207
227
|
this.clearReconnectTimer();
|
|
228
|
+
this.clearReconnectDelay();
|
|
208
229
|
}
|
|
209
230
|
async sleep(delayMs) {
|
|
210
231
|
await new Promise((resolve) => {
|
|
@@ -214,8 +235,10 @@ export class DingTalkBot {
|
|
|
214
235
|
}
|
|
215
236
|
async waitForDelay(delayMs) {
|
|
216
237
|
await new Promise((resolve) => {
|
|
217
|
-
this.
|
|
218
|
-
|
|
238
|
+
this.reconnectDelayResolve = resolve;
|
|
239
|
+
this.reconnectDelayTimer = this.setTrackedTimeout(() => {
|
|
240
|
+
this.reconnectDelayTimer = null;
|
|
241
|
+
this.reconnectDelayResolve = null;
|
|
219
242
|
resolve();
|
|
220
243
|
}, delayMs);
|
|
221
244
|
});
|
|
@@ -299,6 +322,13 @@ export class DingTalkBot {
|
|
|
299
322
|
if (this.isStopped) {
|
|
300
323
|
return;
|
|
301
324
|
}
|
|
325
|
+
// An attempt is already in flight; it owns the retry loop and will
|
|
326
|
+
// reschedule itself on failure. Scheduling here would be redundant and,
|
|
327
|
+
// worse, tear down a just-established socket if the attempt has already
|
|
328
|
+
// succeeded by the time this fires.
|
|
329
|
+
if (this.isReconnecting) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
302
332
|
this.clearReconnectTimer();
|
|
303
333
|
this.reconnectTimer = this.setTrackedTimeout(() => {
|
|
304
334
|
this.reconnectTimer = null;
|
|
@@ -405,7 +435,13 @@ export class DingTalkBot {
|
|
|
405
435
|
return;
|
|
406
436
|
const elapsed = Date.now() - this.lastSocketAvailableTime;
|
|
407
437
|
if (elapsed > 90 * 1000 && !this.activeMessageProcessing) {
|
|
408
|
-
|
|
438
|
+
// No pong / activity for >90s: the socket is (half-)dead and may
|
|
439
|
+
// never emit a close event. Proactively force a reconnect instead
|
|
440
|
+
// of waiting indefinitely. scheduleReconnect no-ops if an attempt
|
|
441
|
+
// is already in flight or the bot has stopped.
|
|
442
|
+
log.logWarning("DingTalk: connection timeout detected (>90s); forcing reconnect.");
|
|
443
|
+
this.scheduleReconnect(1000, true);
|
|
444
|
+
return;
|
|
409
445
|
}
|
|
410
446
|
try {
|
|
411
447
|
const s = this.getSocket();
|
package/package.json
CHANGED