asyx 0.5.6 → 0.5.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.
- package/README.md +2 -0
- package/package.json +1 -1
- package/src/control-plane/MqttControlPlaneClient.js +45 -12
package/README.md
CHANGED
|
@@ -168,6 +168,8 @@ asyx tunnel --minecraft [--port <n>] [--name <alias>]
|
|
|
168
168
|
|
|
169
169
|
## What's new in 0.5.x
|
|
170
170
|
|
|
171
|
+
**DNS outage keeps the tunnel up (0.5.7)** — if the IoT hostname fails to resolve, the CLI waits and retries instead of exiting after 20 immediate attempts.
|
|
172
|
+
|
|
171
173
|
**Refresh after a control-plane reconnect (0.5.6)** — if the MQTT control connection drops and the client id rotates, the next lease refresh keeps the tunnel up instead of exiting with `jwt_refresh_failed`.
|
|
172
174
|
|
|
173
175
|
**Reconnect after a DNS blip (0.5.5)** — if the network drops before the MQTT TLS handshake, the CLI stays up and uses the reconnect it already scheduled.
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@ import mqtt from 'mqtt';
|
|
|
14
14
|
import { ulid } from 'ulid';
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* @typedef {'soft' | 'hard'} MqttFaultKind
|
|
17
|
+
* @typedef {'soft' | 'hard' | 'transient'} MqttFaultKind
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
/**
|
|
@@ -66,6 +66,7 @@ export class MqttControlPlaneClient {
|
|
|
66
66
|
this.shuttingDown = false;
|
|
67
67
|
this.mqttOnline = false;
|
|
68
68
|
this.hardErrorCount = 0;
|
|
69
|
+
this.transientErrorCount = 0;
|
|
69
70
|
this.reconnectTimer = null;
|
|
70
71
|
this.connectStartTime = null;
|
|
71
72
|
this.reconnectAttempts = 0; // Track total reconnect attempts
|
|
@@ -364,6 +365,7 @@ export class MqttControlPlaneClient {
|
|
|
364
365
|
this.clearWatchdog();
|
|
365
366
|
this.mqttOnline = true;
|
|
366
367
|
this.hardErrorCount = 0;
|
|
368
|
+
this.transientErrorCount = 0;
|
|
367
369
|
this.reconnectAttempts = 0; // Reset on successful connect
|
|
368
370
|
this.connectStartTime = null;
|
|
369
371
|
|
|
@@ -678,6 +680,12 @@ export class MqttControlPlaneClient {
|
|
|
678
680
|
const name = (err && (err.name)) || "";
|
|
679
681
|
const msg = (err && (err.message)) || "";
|
|
680
682
|
|
|
683
|
+
// Resolver failures recover, including before the MQTT handshake.
|
|
684
|
+
// The 20-attempt exit is for auth and policy failures that will not.
|
|
685
|
+
if (code === "ENOTFOUND" || code === "EAI_AGAIN") {
|
|
686
|
+
return "transient";
|
|
687
|
+
}
|
|
688
|
+
|
|
681
689
|
// If close/end fires before connect, it's likely a hard fault (auth/policy issue)
|
|
682
690
|
if (beforeConnect) {
|
|
683
691
|
return "hard";
|
|
@@ -739,6 +747,20 @@ export class MqttControlPlaneClient {
|
|
|
739
747
|
const reason = err?.message || err?.code || kind;
|
|
740
748
|
this.onOffline?.(reason);
|
|
741
749
|
|
|
750
|
+
if (kind === "transient") {
|
|
751
|
+
this.transientErrorCount++;
|
|
752
|
+
this.logger?.debug('mqtt.control_plane.fault.transient', {
|
|
753
|
+
transientErrorCount: this.transientErrorCount,
|
|
754
|
+
reconnectAttempts: this.reconnectAttempts,
|
|
755
|
+
reason,
|
|
756
|
+
clientId: this.currentClientId,
|
|
757
|
+
baseClientId: this.baseClientId
|
|
758
|
+
});
|
|
759
|
+
this.forceCloseClient();
|
|
760
|
+
this.scheduleReconnect(/* immediate */ false, { transient: true });
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
|
|
742
764
|
if (kind === "hard") {
|
|
743
765
|
this.hardErrorCount++;
|
|
744
766
|
this.reconnectAttempts++;
|
|
@@ -837,26 +859,37 @@ export class MqttControlPlaneClient {
|
|
|
837
859
|
/**
|
|
838
860
|
* Schedule reconnect with jittered backoff.
|
|
839
861
|
* @param {boolean} immediate - true for hard faults (ECONNRESET, etc.), false for soft
|
|
862
|
+
* @param {{ transient?: boolean }} [options] - transient resolver failures use a growing delay
|
|
840
863
|
*/
|
|
841
|
-
scheduleReconnect(immediate) {
|
|
864
|
+
scheduleReconnect(immediate, options = {}) {
|
|
842
865
|
if (this.shuttingDown) return;
|
|
843
866
|
if (this.reconnectTimer) return; // already scheduled
|
|
844
867
|
|
|
845
|
-
const
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
this.
|
|
852
|
-
|
|
853
|
-
|
|
868
|
+
const transient = options.transient === true;
|
|
869
|
+
let delay;
|
|
870
|
+
if (transient) {
|
|
871
|
+
const expFactor = Math.min(Math.max(this.transientErrorCount - 1, 0), 4);
|
|
872
|
+
const delayNoJitter = 1000 * Math.pow(2, expFactor);
|
|
873
|
+
const jitter = Math.random() * 200; // 0-200ms jitter
|
|
874
|
+
delay = Math.min(this.maxReconnectDelayMs, delayNoJitter + jitter);
|
|
875
|
+
} else {
|
|
876
|
+
const base = immediate ? 0 : 200;
|
|
877
|
+
const expFactor = Math.min(this.hardErrorCount, 5);
|
|
878
|
+
const delayNoJitter =
|
|
879
|
+
this.hardErrorCount === 0 ? base : base * Math.pow(2, expFactor);
|
|
880
|
+
const jitter = Math.random() * 200; // 0-200ms jitter
|
|
881
|
+
delay =
|
|
882
|
+
this.hardErrorCount === 0
|
|
883
|
+
? base
|
|
884
|
+
: Math.min(this.maxReconnectDelayMs, delayNoJitter + jitter);
|
|
885
|
+
}
|
|
854
886
|
|
|
855
887
|
// QPA-CLI-10: Telemetry logs default to debug for quiet mode
|
|
856
888
|
this.logger?.debug('mqtt.control_plane.reconnect.scheduled', {
|
|
857
|
-
immediate,
|
|
889
|
+
immediate: transient ? false : immediate,
|
|
858
890
|
delay,
|
|
859
891
|
hardErrorCount: this.hardErrorCount,
|
|
892
|
+
transientErrorCount: this.transientErrorCount,
|
|
860
893
|
attempt: this.hardErrorCount + 1
|
|
861
894
|
});
|
|
862
895
|
|