tuna-agent 0.1.166 → 0.1.167
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.
- package/dist/daemon/ws-client.js +12 -0
- package/package.json +1 -1
package/dist/daemon/ws-client.js
CHANGED
|
@@ -224,6 +224,18 @@ export class AgentWebSocketClient {
|
|
|
224
224
|
return this.ws !== null && this.ws.readyState === WebSocket.OPEN;
|
|
225
225
|
}
|
|
226
226
|
_connect() {
|
|
227
|
+
// Tear down any previous socket first. Without this, a reconnect could leak the
|
|
228
|
+
// old connection: it stays half-open on the server (readyState OPEN) and becomes
|
|
229
|
+
// a zombie the API keeps sending to, while this daemon listens on the new one.
|
|
230
|
+
if (this.ws) {
|
|
231
|
+
try {
|
|
232
|
+
this.ws.removeAllListeners();
|
|
233
|
+
this.ws.terminate();
|
|
234
|
+
}
|
|
235
|
+
catch { /* ignore */ }
|
|
236
|
+
this.ws = null;
|
|
237
|
+
}
|
|
238
|
+
this._stopHeartbeat();
|
|
227
239
|
try {
|
|
228
240
|
this.ws = new WebSocket(this.config.wsUrl, {
|
|
229
241
|
headers: { 'Authorization': `Bearer ${this.config.agentToken}` },
|