@replit/river 0.15.0 → 0.15.2
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 +41 -22
- package/dist/{builder-ca6c4259.d.ts → builder-ebd945c0.d.ts} +1 -1
- package/dist/{chunk-IVNV5HBI.js → chunk-B7VTDQR7.js} +160 -51
- package/dist/{chunk-BSAIT634.js → chunk-UJHTHOTT.js} +1 -1
- package/dist/{chunk-FFT7PSUV.js → chunk-ZRB6IKPV.js} +1 -1
- package/dist/{connection-0c5eeb14.d.ts → connection-10a24478.d.ts} +1 -1
- package/dist/{connection-14675d77.d.ts → connection-f4492948.d.ts} +1 -1
- package/dist/{index-f922ec84.d.ts → index-bbccacef.d.ts} +90 -16
- package/dist/router/index.d.cts +3 -3
- package/dist/router/index.d.ts +3 -3
- package/dist/transport/impls/uds/client.cjs +206 -92
- package/dist/transport/impls/uds/client.d.cts +3 -3
- package/dist/transport/impls/uds/client.d.ts +3 -3
- package/dist/transport/impls/uds/client.js +2 -2
- package/dist/transport/impls/uds/server.cjs +75 -73
- package/dist/transport/impls/uds/server.d.cts +3 -3
- package/dist/transport/impls/uds/server.d.ts +3 -3
- package/dist/transport/impls/uds/server.js +2 -2
- package/dist/transport/impls/ws/client.cjs +206 -94
- package/dist/transport/impls/ws/client.d.cts +3 -3
- package/dist/transport/impls/ws/client.d.ts +3 -3
- package/dist/transport/impls/ws/client.js +2 -2
- package/dist/transport/impls/ws/server.cjs +75 -73
- package/dist/transport/impls/ws/server.d.cts +3 -3
- package/dist/transport/impls/ws/server.d.ts +3 -3
- package/dist/transport/impls/ws/server.js +2 -2
- package/dist/transport/index.cjs +211 -105
- package/dist/transport/index.d.cts +1 -1
- package/dist/transport/index.d.ts +1 -1
- package/dist/transport/index.js +3 -3
- package/dist/util/testHelpers.cjs +61 -64
- package/dist/util/testHelpers.d.cts +10 -4
- package/dist/util/testHelpers.d.ts +10 -4
- package/dist/util/testHelpers.js +13 -5
- package/package.json +1 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Server, Socket } from 'node:net';
|
|
2
|
-
import { S as ServerTransport, b as TransportClientId,
|
|
3
|
-
import { U as UdsConnection } from '../../../connection-
|
|
2
|
+
import { S as ServerTransport, b as TransportClientId, d as ProvidedTransportOptions } from '../../../index-bbccacef.js';
|
|
3
|
+
import { U as UdsConnection } from '../../../connection-10a24478.js';
|
|
4
4
|
import '../../../types-3e5768ec.js';
|
|
5
5
|
import '@sinclair/typebox';
|
|
6
6
|
import 'node:stream';
|
|
7
7
|
|
|
8
8
|
declare class UnixDomainSocketServerTransport extends ServerTransport<UdsConnection> {
|
|
9
9
|
server: Server;
|
|
10
|
-
constructor(server: Server, clientId: TransportClientId, providedOptions?: Partial<
|
|
10
|
+
constructor(server: Server, clientId: TransportClientId, providedOptions?: Partial<ProvidedTransportOptions>);
|
|
11
11
|
connectionHandler: (sock: Socket) => void;
|
|
12
12
|
close(): void;
|
|
13
13
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Server, Socket } from 'node:net';
|
|
2
|
-
import { S as ServerTransport, b as TransportClientId,
|
|
3
|
-
import { U as UdsConnection } from '../../../connection-
|
|
2
|
+
import { S as ServerTransport, b as TransportClientId, d as ProvidedTransportOptions } from '../../../index-bbccacef.js';
|
|
3
|
+
import { U as UdsConnection } from '../../../connection-10a24478.js';
|
|
4
4
|
import '../../../types-3e5768ec.js';
|
|
5
5
|
import '@sinclair/typebox';
|
|
6
6
|
import 'node:stream';
|
|
7
7
|
|
|
8
8
|
declare class UnixDomainSocketServerTransport extends ServerTransport<UdsConnection> {
|
|
9
9
|
server: Server;
|
|
10
|
-
constructor(server: Server, clientId: TransportClientId, providedOptions?: Partial<
|
|
10
|
+
constructor(server: Server, clientId: TransportClientId, providedOptions?: Partial<ProvidedTransportOptions>);
|
|
11
11
|
connectionHandler: (sock: Socket) => void;
|
|
12
12
|
close(): void;
|
|
13
13
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UdsConnection
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-UJHTHOTT.js";
|
|
4
4
|
import {
|
|
5
5
|
ServerTransport
|
|
6
|
-
} from "../../../chunk-
|
|
6
|
+
} from "../../../chunk-B7VTDQR7.js";
|
|
7
7
|
import "../../../chunk-GFRAOY75.js";
|
|
8
8
|
import {
|
|
9
9
|
log
|
|
@@ -100,6 +100,11 @@ function isAck(controlFlag) {
|
|
|
100
100
|
var log;
|
|
101
101
|
|
|
102
102
|
// transport/events.ts
|
|
103
|
+
var ProtocolError = {
|
|
104
|
+
RetriesExceeded: "conn_retry_exceeded",
|
|
105
|
+
HandshakeFailed: "handshake_failed",
|
|
106
|
+
UseAfterDestroy: "use_after_destroy"
|
|
107
|
+
};
|
|
103
108
|
var EventDispatcher = class {
|
|
104
109
|
eventListeners = {};
|
|
105
110
|
numberOfListeners(eventType) {
|
|
@@ -129,60 +134,6 @@ var EventDispatcher = class {
|
|
|
129
134
|
|
|
130
135
|
// transport/session.ts
|
|
131
136
|
var import_nanoid2 = require("nanoid");
|
|
132
|
-
|
|
133
|
-
// codec/json.ts
|
|
134
|
-
var encoder = new TextEncoder();
|
|
135
|
-
var decoder = new TextDecoder();
|
|
136
|
-
function uint8ArrayToBase64(uint8Array) {
|
|
137
|
-
let binary = "";
|
|
138
|
-
uint8Array.forEach((byte) => {
|
|
139
|
-
binary += String.fromCharCode(byte);
|
|
140
|
-
});
|
|
141
|
-
return btoa(binary);
|
|
142
|
-
}
|
|
143
|
-
function base64ToUint8Array(base64) {
|
|
144
|
-
const binaryString = atob(base64);
|
|
145
|
-
const uint8Array = new Uint8Array(binaryString.length);
|
|
146
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
147
|
-
uint8Array[i] = binaryString.charCodeAt(i);
|
|
148
|
-
}
|
|
149
|
-
return uint8Array;
|
|
150
|
-
}
|
|
151
|
-
var NaiveJsonCodec = {
|
|
152
|
-
toBuffer: (obj) => {
|
|
153
|
-
return encoder.encode(
|
|
154
|
-
JSON.stringify(obj, function replacer(key) {
|
|
155
|
-
const val = this[key];
|
|
156
|
-
if (val instanceof Uint8Array) {
|
|
157
|
-
return { $t: uint8ArrayToBase64(val) };
|
|
158
|
-
} else {
|
|
159
|
-
return val;
|
|
160
|
-
}
|
|
161
|
-
})
|
|
162
|
-
);
|
|
163
|
-
},
|
|
164
|
-
fromBuffer: (buff) => {
|
|
165
|
-
try {
|
|
166
|
-
const parsed = JSON.parse(
|
|
167
|
-
decoder.decode(buff),
|
|
168
|
-
function reviver(_key, val) {
|
|
169
|
-
if (val?.$t) {
|
|
170
|
-
return base64ToUint8Array(val.$t);
|
|
171
|
-
} else {
|
|
172
|
-
return val;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
);
|
|
176
|
-
if (typeof parsed === "object")
|
|
177
|
-
return parsed;
|
|
178
|
-
return null;
|
|
179
|
-
} catch {
|
|
180
|
-
return null;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
// transport/session.ts
|
|
186
137
|
var nanoid2 = (0, import_nanoid2.customAlphabet)("1234567890abcdefghijklmnopqrstuvxyz", 6);
|
|
187
138
|
var unsafeId = () => nanoid2();
|
|
188
139
|
var Connection = class {
|
|
@@ -191,15 +142,6 @@ var Connection = class {
|
|
|
191
142
|
this.debugId = `conn-${unsafeId()}`;
|
|
192
143
|
}
|
|
193
144
|
};
|
|
194
|
-
var HEARTBEAT_INTERVAL_MS = 1e3;
|
|
195
|
-
var HEARTBEATS_TILL_DEAD = 2;
|
|
196
|
-
var SESSION_DISCONNECT_GRACE_MS = 5e3;
|
|
197
|
-
var defaultSessionOptions = {
|
|
198
|
-
heartbeatIntervalMs: HEARTBEAT_INTERVAL_MS,
|
|
199
|
-
heartbeatsUntilDead: HEARTBEATS_TILL_DEAD,
|
|
200
|
-
sessionDisconnectGraceMs: SESSION_DISCONNECT_GRACE_MS,
|
|
201
|
-
codec: NaiveJsonCodec
|
|
202
|
-
};
|
|
203
145
|
var Session = class {
|
|
204
146
|
codec;
|
|
205
147
|
options;
|
|
@@ -394,14 +336,146 @@ function coerceErrorString(err) {
|
|
|
394
336
|
return `[coerced to error] ${String(err)}`;
|
|
395
337
|
}
|
|
396
338
|
|
|
339
|
+
// transport/rateLimit.ts
|
|
340
|
+
var LeakyBucketRateLimit = class {
|
|
341
|
+
budgetConsumed;
|
|
342
|
+
intervalHandles;
|
|
343
|
+
options;
|
|
344
|
+
constructor(options) {
|
|
345
|
+
this.options = options;
|
|
346
|
+
this.budgetConsumed = /* @__PURE__ */ new Map();
|
|
347
|
+
this.intervalHandles = /* @__PURE__ */ new Map();
|
|
348
|
+
}
|
|
349
|
+
getBackoffMs(user) {
|
|
350
|
+
if (!this.budgetConsumed.has(user))
|
|
351
|
+
return 0;
|
|
352
|
+
const exponent = Math.max(0, this.getBudgetConsumed(user) - 1);
|
|
353
|
+
const jitter = Math.floor(Math.random() * this.options.maxJitterMs);
|
|
354
|
+
const backoffMs = Math.min(
|
|
355
|
+
this.options.baseIntervalMs * 2 ** exponent,
|
|
356
|
+
this.options.maxBackoffMs
|
|
357
|
+
);
|
|
358
|
+
return backoffMs + jitter;
|
|
359
|
+
}
|
|
360
|
+
get totalBudgetRestoreTime() {
|
|
361
|
+
return this.options.budgetRestoreIntervalMs * this.options.attemptBudgetCapacity;
|
|
362
|
+
}
|
|
363
|
+
consumeBudget(user) {
|
|
364
|
+
this.stopLeak(user);
|
|
365
|
+
this.budgetConsumed.set(user, this.getBudgetConsumed(user) + 1);
|
|
366
|
+
}
|
|
367
|
+
getBudgetConsumed(user) {
|
|
368
|
+
return this.budgetConsumed.get(user) ?? 0;
|
|
369
|
+
}
|
|
370
|
+
hasBudget(user) {
|
|
371
|
+
return this.getBudgetConsumed(user) < this.options.attemptBudgetCapacity;
|
|
372
|
+
}
|
|
373
|
+
startRestoringBudget(user) {
|
|
374
|
+
if (this.intervalHandles.has(user)) {
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
const restoreBudgetForUser = () => {
|
|
378
|
+
const currentBudget = this.budgetConsumed.get(user);
|
|
379
|
+
if (!currentBudget) {
|
|
380
|
+
this.stopLeak(user);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
const newBudget = currentBudget - 1;
|
|
384
|
+
if (newBudget === 0) {
|
|
385
|
+
this.budgetConsumed.delete(user);
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
this.budgetConsumed.set(user, newBudget);
|
|
389
|
+
};
|
|
390
|
+
restoreBudgetForUser();
|
|
391
|
+
const intervalHandle = setInterval(
|
|
392
|
+
restoreBudgetForUser,
|
|
393
|
+
this.options.budgetRestoreIntervalMs
|
|
394
|
+
);
|
|
395
|
+
this.intervalHandles.set(user, intervalHandle);
|
|
396
|
+
}
|
|
397
|
+
stopLeak(user) {
|
|
398
|
+
if (!this.intervalHandles.has(user)) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
clearInterval(this.intervalHandles.get(user));
|
|
402
|
+
this.intervalHandles.delete(user);
|
|
403
|
+
}
|
|
404
|
+
close() {
|
|
405
|
+
for (const user of this.intervalHandles.keys()) {
|
|
406
|
+
this.stopLeak(user);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
// codec/json.ts
|
|
412
|
+
var encoder = new TextEncoder();
|
|
413
|
+
var decoder = new TextDecoder();
|
|
414
|
+
function uint8ArrayToBase64(uint8Array) {
|
|
415
|
+
let binary = "";
|
|
416
|
+
uint8Array.forEach((byte) => {
|
|
417
|
+
binary += String.fromCharCode(byte);
|
|
418
|
+
});
|
|
419
|
+
return btoa(binary);
|
|
420
|
+
}
|
|
421
|
+
function base64ToUint8Array(base64) {
|
|
422
|
+
const binaryString = atob(base64);
|
|
423
|
+
const uint8Array = new Uint8Array(binaryString.length);
|
|
424
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
425
|
+
uint8Array[i] = binaryString.charCodeAt(i);
|
|
426
|
+
}
|
|
427
|
+
return uint8Array;
|
|
428
|
+
}
|
|
429
|
+
var NaiveJsonCodec = {
|
|
430
|
+
toBuffer: (obj) => {
|
|
431
|
+
return encoder.encode(
|
|
432
|
+
JSON.stringify(obj, function replacer(key) {
|
|
433
|
+
const val = this[key];
|
|
434
|
+
if (val instanceof Uint8Array) {
|
|
435
|
+
return { $t: uint8ArrayToBase64(val) };
|
|
436
|
+
} else {
|
|
437
|
+
return val;
|
|
438
|
+
}
|
|
439
|
+
})
|
|
440
|
+
);
|
|
441
|
+
},
|
|
442
|
+
fromBuffer: (buff) => {
|
|
443
|
+
try {
|
|
444
|
+
const parsed = JSON.parse(
|
|
445
|
+
decoder.decode(buff),
|
|
446
|
+
function reviver(_key, val) {
|
|
447
|
+
if (val?.$t) {
|
|
448
|
+
return base64ToUint8Array(val.$t);
|
|
449
|
+
} else {
|
|
450
|
+
return val;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
);
|
|
454
|
+
if (typeof parsed === "object")
|
|
455
|
+
return parsed;
|
|
456
|
+
return null;
|
|
457
|
+
} catch {
|
|
458
|
+
return null;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
|
|
397
463
|
// transport/transport.ts
|
|
398
|
-
var RECONNECT_JITTER_MAX_MS = 500;
|
|
399
|
-
var RECONNECT_INTERVAL_MS = 250;
|
|
400
464
|
var defaultTransportOptions = {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
465
|
+
heartbeatIntervalMs: 1e3,
|
|
466
|
+
heartbeatsUntilDead: 2,
|
|
467
|
+
sessionDisconnectGraceMs: 5e3,
|
|
468
|
+
codec: NaiveJsonCodec
|
|
469
|
+
};
|
|
470
|
+
var defaultClientTransportOptions = {
|
|
471
|
+
connectionRetryOptions: {
|
|
472
|
+
baseIntervalMs: 250,
|
|
473
|
+
maxJitterMs: 200,
|
|
474
|
+
maxBackoffMs: 32e3,
|
|
475
|
+
attemptBudgetCapacity: 15,
|
|
476
|
+
budgetRestoreIntervalMs: 200
|
|
477
|
+
},
|
|
478
|
+
...defaultTransportOptions
|
|
405
479
|
};
|
|
406
480
|
var Transport = class {
|
|
407
481
|
/**
|
|
@@ -616,7 +690,7 @@ var Transport = class {
|
|
|
616
690
|
if (this.state === "destroyed") {
|
|
617
691
|
const err = "transport is destroyed, cant send";
|
|
618
692
|
log?.error(`${this.clientId} -- ` + err + `: ${JSON.stringify(msg)}`);
|
|
619
|
-
this.protocolError(
|
|
693
|
+
this.protocolError(ProtocolError.UseAfterDestroy, err);
|
|
620
694
|
return void 0;
|
|
621
695
|
} else if (this.state === "closed") {
|
|
622
696
|
log?.info(
|
|
@@ -676,14 +750,26 @@ var Transport = class {
|
|
|
676
750
|
}
|
|
677
751
|
};
|
|
678
752
|
var ClientTransport = class extends Transport {
|
|
753
|
+
/**
|
|
754
|
+
* The options for this transport.
|
|
755
|
+
*/
|
|
756
|
+
options;
|
|
679
757
|
/**
|
|
680
758
|
* The map of reconnect promises for each client ID.
|
|
681
759
|
*/
|
|
682
760
|
inflightConnectionPromises;
|
|
761
|
+
retryBudget;
|
|
683
762
|
tryReconnecting = true;
|
|
684
763
|
constructor(clientId, providedOptions) {
|
|
685
764
|
super(clientId, providedOptions);
|
|
765
|
+
this.options = {
|
|
766
|
+
...defaultClientTransportOptions,
|
|
767
|
+
...providedOptions
|
|
768
|
+
};
|
|
686
769
|
this.inflightConnectionPromises = /* @__PURE__ */ new Map();
|
|
770
|
+
this.retryBudget = new LeakyBucketRateLimit(
|
|
771
|
+
this.options.connectionRetryOptions
|
|
772
|
+
);
|
|
687
773
|
}
|
|
688
774
|
handleConnection(conn, to) {
|
|
689
775
|
if (this.state !== "open")
|
|
@@ -714,7 +800,10 @@ var ClientTransport = class extends Transport {
|
|
|
714
800
|
log?.info(
|
|
715
801
|
`${this.clientId} -- connection (id: ${conn.debugId}) to ${to} disconnected`
|
|
716
802
|
);
|
|
717
|
-
|
|
803
|
+
this.inflightConnectionPromises.delete(to);
|
|
804
|
+
if (this.tryReconnecting) {
|
|
805
|
+
void this.connect(to);
|
|
806
|
+
}
|
|
718
807
|
});
|
|
719
808
|
conn.addErrorListener((err) => {
|
|
720
809
|
log?.warn(
|
|
@@ -726,7 +815,7 @@ var ClientTransport = class extends Transport {
|
|
|
726
815
|
const parsed = this.parseMsg(data);
|
|
727
816
|
if (!parsed) {
|
|
728
817
|
this.protocolError(
|
|
729
|
-
|
|
818
|
+
ProtocolError.HandshakeFailed,
|
|
730
819
|
"received non-transport message"
|
|
731
820
|
);
|
|
732
821
|
return false;
|
|
@@ -738,7 +827,7 @@ var ClientTransport = class extends Transport {
|
|
|
738
827
|
)}`
|
|
739
828
|
);
|
|
740
829
|
this.protocolError(
|
|
741
|
-
|
|
830
|
+
ProtocolError.HandshakeFailed,
|
|
742
831
|
"invalid handshake resp"
|
|
743
832
|
);
|
|
744
833
|
return false;
|
|
@@ -750,7 +839,7 @@ var ClientTransport = class extends Transport {
|
|
|
750
839
|
)}`
|
|
751
840
|
);
|
|
752
841
|
this.protocolError(
|
|
753
|
-
|
|
842
|
+
ProtocolError.HandshakeFailed,
|
|
754
843
|
parsed.payload.status.reason
|
|
755
844
|
);
|
|
756
845
|
return false;
|
|
@@ -765,41 +854,64 @@ var ClientTransport = class extends Transport {
|
|
|
765
854
|
* Manually attempts to connect to a client.
|
|
766
855
|
* @param to The client ID of the node to connect to.
|
|
767
856
|
*/
|
|
768
|
-
async connect(to
|
|
769
|
-
|
|
857
|
+
async connect(to) {
|
|
858
|
+
const canProceedWithConnection = () => this.state === "open";
|
|
859
|
+
if (!canProceedWithConnection()) {
|
|
770
860
|
log?.info(
|
|
771
|
-
`${this.clientId} -- transport state is no longer open,
|
|
861
|
+
`${this.clientId} -- transport state is no longer open, cancelling attempt to connect to ${to}`
|
|
772
862
|
);
|
|
773
863
|
return;
|
|
774
864
|
}
|
|
775
865
|
let reconnectPromise = this.inflightConnectionPromises.get(to);
|
|
776
866
|
if (!reconnectPromise) {
|
|
777
|
-
|
|
867
|
+
log?.info(`${this.clientId} -- attempting connection to ${to}`);
|
|
868
|
+
const budgetConsumed = this.retryBudget.getBudgetConsumed(to);
|
|
869
|
+
if (!this.retryBudget.hasBudget(to)) {
|
|
870
|
+
const errMsg = `not attempting to connect to ${to}, retry budget exceeded (more than ${budgetConsumed} attempts in the last ${this.retryBudget.totalBudgetRestoreTime}ms)`;
|
|
871
|
+
log?.warn(`${this.clientId} -- ${errMsg}`);
|
|
872
|
+
this.protocolError(ProtocolError.RetriesExceeded, errMsg);
|
|
873
|
+
return;
|
|
874
|
+
}
|
|
875
|
+
let sleep = Promise.resolve();
|
|
876
|
+
const backoffMs = this.retryBudget.getBackoffMs(to);
|
|
877
|
+
if (backoffMs > 0) {
|
|
878
|
+
sleep = new Promise((resolve) => setTimeout(resolve, backoffMs));
|
|
879
|
+
}
|
|
880
|
+
this.retryBudget.consumeBudget(to);
|
|
881
|
+
reconnectPromise = sleep.then(() => {
|
|
882
|
+
if (!canProceedWithConnection()) {
|
|
883
|
+
throw new Error("transport state is no longer open");
|
|
884
|
+
}
|
|
885
|
+
}).then(() => this.createNewOutgoingConnection(to)).then((conn) => {
|
|
886
|
+
if (!canProceedWithConnection()) {
|
|
887
|
+
log?.info(
|
|
888
|
+
`${this.clientId} -- transport state is no longer open, closing pre-handshake connection (id: ${conn.debugId}) to ${to}`
|
|
889
|
+
);
|
|
890
|
+
conn.close();
|
|
891
|
+
throw new Error("transport state is no longer open");
|
|
892
|
+
}
|
|
893
|
+
this.retryBudget.startRestoringBudget(to);
|
|
778
894
|
this.sendHandshake(to, conn);
|
|
779
895
|
return conn;
|
|
780
896
|
});
|
|
781
897
|
this.inflightConnectionPromises.set(to, reconnectPromise);
|
|
898
|
+
} else {
|
|
899
|
+
log?.info(
|
|
900
|
+
`${this.clientId} -- attempting connection to ${to} (reusing previous attempt)`
|
|
901
|
+
);
|
|
782
902
|
}
|
|
783
903
|
try {
|
|
784
904
|
await reconnectPromise;
|
|
785
905
|
} catch (error) {
|
|
786
|
-
const errStr = coerceErrorString(error);
|
|
787
906
|
this.inflightConnectionPromises.delete(to);
|
|
788
|
-
const
|
|
789
|
-
if (!
|
|
790
|
-
|
|
791
|
-
if (attempt >= this.options.retryAttemptsMax) {
|
|
792
|
-
const errMsg = `connection to ${to} failed after ${attempt} attempts (${errStr}), giving up`;
|
|
793
|
-
log?.error(`${this.clientId} -- ${errMsg}`);
|
|
794
|
-
this.protocolError("conn_retry_exceeded" /* RetriesExceeded */, errMsg);
|
|
795
|
-
return;
|
|
907
|
+
const errStr = coerceErrorString(error);
|
|
908
|
+
if (!this.tryReconnecting || !canProceedWithConnection()) {
|
|
909
|
+
log?.warn(`${this.clientId} -- connection to ${to} failed (${errStr})`);
|
|
796
910
|
} else {
|
|
797
|
-
const jitter = Math.floor(Math.random() * this.options.retryJitterMs);
|
|
798
|
-
const backoffMs = this.options.retryIntervalMs * 2 ** attempt + jitter;
|
|
799
911
|
log?.warn(
|
|
800
|
-
`${this.clientId} -- connection to ${to} failed (${errStr}),
|
|
912
|
+
`${this.clientId} -- connection to ${to} failed (${errStr}), retrying`
|
|
801
913
|
);
|
|
802
|
-
|
|
914
|
+
return this.connect(to);
|
|
803
915
|
}
|
|
804
916
|
}
|
|
805
917
|
}
|
|
@@ -812,9 +924,9 @@ var ClientTransport = class extends Transport {
|
|
|
812
924
|
log?.debug(`${this.clientId} -- sending handshake request to ${to}`);
|
|
813
925
|
conn.send(this.codec.toBuffer(requestMsg));
|
|
814
926
|
}
|
|
815
|
-
|
|
816
|
-
this.
|
|
817
|
-
super.
|
|
927
|
+
close() {
|
|
928
|
+
this.retryBudget.close();
|
|
929
|
+
super.close();
|
|
818
930
|
}
|
|
819
931
|
};
|
|
820
932
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import WebSocket from 'isomorphic-ws';
|
|
2
|
-
import { a as ClientTransport, b as TransportClientId, c as
|
|
3
|
-
import { W as WebSocketConnection } from '../../../connection-
|
|
2
|
+
import { a as ClientTransport, b as TransportClientId, c as ProvidedClientTransportOptions } from '../../../index-bbccacef.js';
|
|
3
|
+
import { W as WebSocketConnection } from '../../../connection-f4492948.js';
|
|
4
4
|
import '../../../types-3e5768ec.js';
|
|
5
5
|
import '@sinclair/typebox';
|
|
6
6
|
|
|
@@ -21,7 +21,7 @@ declare class WebSocketClientTransport extends ClientTransport<WebSocketConnecti
|
|
|
21
21
|
* @param serverId The ID of the server this transport is connecting to.
|
|
22
22
|
* @param providedOptions An optional object containing configuration options for the transport.
|
|
23
23
|
*/
|
|
24
|
-
constructor(wsGetter: () => Promise<WebSocket>, clientId: TransportClientId, providedOptions?:
|
|
24
|
+
constructor(wsGetter: () => Promise<WebSocket>, clientId: TransportClientId, providedOptions?: ProvidedClientTransportOptions);
|
|
25
25
|
createNewOutgoingConnection(to: string): Promise<WebSocketConnection>;
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import WebSocket from 'isomorphic-ws';
|
|
2
|
-
import { a as ClientTransport, b as TransportClientId, c as
|
|
3
|
-
import { W as WebSocketConnection } from '../../../connection-
|
|
2
|
+
import { a as ClientTransport, b as TransportClientId, c as ProvidedClientTransportOptions } from '../../../index-bbccacef.js';
|
|
3
|
+
import { W as WebSocketConnection } from '../../../connection-f4492948.js';
|
|
4
4
|
import '../../../types-3e5768ec.js';
|
|
5
5
|
import '@sinclair/typebox';
|
|
6
6
|
|
|
@@ -21,7 +21,7 @@ declare class WebSocketClientTransport extends ClientTransport<WebSocketConnecti
|
|
|
21
21
|
* @param serverId The ID of the server this transport is connecting to.
|
|
22
22
|
* @param providedOptions An optional object containing configuration options for the transport.
|
|
23
23
|
*/
|
|
24
|
-
constructor(wsGetter: () => Promise<WebSocket>, clientId: TransportClientId, providedOptions?:
|
|
24
|
+
constructor(wsGetter: () => Promise<WebSocket>, clientId: TransportClientId, providedOptions?: ProvidedClientTransportOptions);
|
|
25
25
|
createNewOutgoingConnection(to: string): Promise<WebSocketConnection>;
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
WebSocketConnection
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-ZRB6IKPV.js";
|
|
4
4
|
import {
|
|
5
5
|
ClientTransport
|
|
6
|
-
} from "../../../chunk-
|
|
6
|
+
} from "../../../chunk-B7VTDQR7.js";
|
|
7
7
|
import "../../../chunk-GFRAOY75.js";
|
|
8
8
|
import {
|
|
9
9
|
log
|