@replit/river 0.12.0 → 0.12.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/dist/{chunk-24O3BKZA.js → chunk-55XUAPC6.js} +1 -1
- package/dist/{chunk-ANGOKBE5.js → chunk-CT57CKBS.js} +67 -48
- package/dist/{chunk-4HOR4NUO.js → chunk-NHSJ4RDY.js} +1 -1
- package/dist/{chunk-XOTIAXAH.js → chunk-PIF32FUL.js} +1 -1
- package/dist/{chunk-IUDKWAOK.js → chunk-R6YJHJV7.js} +1 -1
- package/dist/{chunk-WTOIOXB7.js → chunk-XFFS4UOD.js} +5 -3
- package/dist/{connection-2956a1c5.d.ts → connection-bf7811aa.d.ts} +1 -1
- package/dist/{connection-cd963ed5.d.ts → connection-d880aa4a.d.ts} +1 -1
- package/dist/{connection-aaea7c88.d.ts → connection-eb10d250.d.ts} +1 -1
- package/dist/{index-d91775d9.d.ts → index-0c0a69f6.d.ts} +9 -11
- package/dist/router/index.cjs +2 -1
- package/dist/router/index.d.cts +1 -1
- package/dist/router/index.d.ts +1 -1
- package/dist/router/index.js +2 -2
- package/dist/transport/impls/stdio/client.cjs +57 -38
- package/dist/transport/impls/stdio/client.d.cts +2 -2
- package/dist/transport/impls/stdio/client.d.ts +2 -2
- package/dist/transport/impls/stdio/client.js +3 -3
- package/dist/transport/impls/stdio/server.cjs +55 -32
- package/dist/transport/impls/stdio/server.d.cts +2 -2
- package/dist/transport/impls/stdio/server.d.ts +2 -2
- package/dist/transport/impls/stdio/server.js +3 -3
- package/dist/transport/impls/uds/client.cjs +57 -38
- package/dist/transport/impls/uds/client.d.cts +2 -2
- package/dist/transport/impls/uds/client.d.ts +2 -2
- package/dist/transport/impls/uds/client.js +3 -3
- package/dist/transport/impls/uds/server.cjs +55 -32
- package/dist/transport/impls/uds/server.d.cts +2 -2
- package/dist/transport/impls/uds/server.d.ts +2 -2
- package/dist/transport/impls/uds/server.js +3 -3
- package/dist/transport/impls/ws/client.cjs +63 -38
- package/dist/transport/impls/ws/client.d.cts +2 -2
- package/dist/transport/impls/ws/client.d.ts +2 -2
- package/dist/transport/impls/ws/client.js +9 -3
- package/dist/transport/impls/ws/server.cjs +55 -32
- package/dist/transport/impls/ws/server.d.cts +2 -2
- package/dist/transport/impls/ws/server.d.ts +2 -2
- package/dist/transport/impls/ws/server.js +3 -3
- package/dist/transport/index.cjs +71 -50
- package/dist/transport/index.d.cts +1 -1
- package/dist/transport/index.d.ts +1 -1
- package/dist/transport/index.js +2 -2
- package/dist/util/testHelpers.d.cts +1 -1
- package/dist/util/testHelpers.d.ts +1 -1
- package/dist/util/testHelpers.js +2 -2
- package/package.json +1 -1
|
@@ -55,7 +55,8 @@ var ControlMessageCloseSchema = import_typebox.Type.Object({
|
|
|
55
55
|
var PROTOCOL_VERSION = "v1";
|
|
56
56
|
var ControlMessageHandshakeRequestSchema = import_typebox.Type.Object({
|
|
57
57
|
type: import_typebox.Type.Literal("HANDSHAKE_REQ"),
|
|
58
|
-
protocolVersion: import_typebox.Type.Literal(PROTOCOL_VERSION)
|
|
58
|
+
protocolVersion: import_typebox.Type.Literal(PROTOCOL_VERSION),
|
|
59
|
+
instanceId: import_typebox.Type.String()
|
|
59
60
|
});
|
|
60
61
|
var ControlMessageHandshakeResponseSchema = import_typebox.Type.Object({
|
|
61
62
|
type: import_typebox.Type.Literal("HANDSHAKE_RESP"),
|
|
@@ -79,7 +80,7 @@ var ControlMessagePayloadSchema = import_typebox.Type.Union([
|
|
|
79
80
|
var OpaqueTransportMessageSchema = TransportMessageSchema(
|
|
80
81
|
import_typebox.Type.Unknown()
|
|
81
82
|
);
|
|
82
|
-
function bootRequestMessage(from, to) {
|
|
83
|
+
function bootRequestMessage(from, to, instanceId) {
|
|
83
84
|
return {
|
|
84
85
|
id: (0, import_nanoid.nanoid)(),
|
|
85
86
|
from,
|
|
@@ -90,7 +91,8 @@ function bootRequestMessage(from, to) {
|
|
|
90
91
|
controlFlags: 0,
|
|
91
92
|
payload: {
|
|
92
93
|
type: "HANDSHAKE_REQ",
|
|
93
|
-
protocolVersion: PROTOCOL_VERSION
|
|
94
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
95
|
+
instanceId
|
|
94
96
|
}
|
|
95
97
|
};
|
|
96
98
|
}
|
|
@@ -107,9 +109,9 @@ var Connection = class {
|
|
|
107
109
|
this.debugId = `conn-${unsafeId()}`;
|
|
108
110
|
}
|
|
109
111
|
};
|
|
110
|
-
var HEARTBEAT_INTERVAL_MS =
|
|
111
|
-
var HEARTBEATS_TILL_DEAD =
|
|
112
|
-
var SESSION_DISCONNECT_GRACE_MS =
|
|
112
|
+
var HEARTBEAT_INTERVAL_MS = 1e3;
|
|
113
|
+
var HEARTBEATS_TILL_DEAD = 2;
|
|
114
|
+
var SESSION_DISCONNECT_GRACE_MS = 5e3;
|
|
113
115
|
var Session = class {
|
|
114
116
|
codec;
|
|
115
117
|
/**
|
|
@@ -192,11 +194,13 @@ var Session = class {
|
|
|
192
194
|
return fullMsg.id;
|
|
193
195
|
}
|
|
194
196
|
sendHeartbeat() {
|
|
195
|
-
if (this.heartbeatMisses >= HEARTBEATS_TILL_DEAD
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
197
|
+
if (this.heartbeatMisses >= HEARTBEATS_TILL_DEAD) {
|
|
198
|
+
if (this.connection) {
|
|
199
|
+
log?.info(
|
|
200
|
+
`${this.from} -- closing connection (id: ${this.connection.debugId}) to ${this.to} due to inactivity`
|
|
201
|
+
);
|
|
202
|
+
this.closeStaleConnection(this.connection);
|
|
203
|
+
}
|
|
200
204
|
return;
|
|
201
205
|
}
|
|
202
206
|
this.send(
|
|
@@ -233,7 +237,6 @@ var Session = class {
|
|
|
233
237
|
}
|
|
234
238
|
}
|
|
235
239
|
updateBookkeeping(ack, seq) {
|
|
236
|
-
this.heartbeatMisses = 0;
|
|
237
240
|
this.sendBuffer = this.sendBuffer.filter((unacked) => unacked.seq > ack);
|
|
238
241
|
this.ack = seq + 1;
|
|
239
242
|
}
|
|
@@ -265,6 +268,7 @@ var Session = class {
|
|
|
265
268
|
}, SESSION_DISCONNECT_GRACE_MS);
|
|
266
269
|
}
|
|
267
270
|
cancelGrace() {
|
|
271
|
+
this.heartbeatMisses = 0;
|
|
268
272
|
clearTimeout(this.disconnectionGrace);
|
|
269
273
|
}
|
|
270
274
|
get connected() {
|
|
@@ -293,6 +297,7 @@ var Session = class {
|
|
|
293
297
|
*/
|
|
294
298
|
halfCloseConnection() {
|
|
295
299
|
this.connection?.close();
|
|
300
|
+
clearInterval(this.heartbeat);
|
|
296
301
|
}
|
|
297
302
|
inspectSendBuffer() {
|
|
298
303
|
return this.sendBuffer;
|
|
@@ -496,6 +501,13 @@ var defaultTransportOptions = {
|
|
|
496
501
|
codec: NaiveJsonCodec
|
|
497
502
|
};
|
|
498
503
|
var Transport = class {
|
|
504
|
+
/**
|
|
505
|
+
* Unique per instance of the transport.
|
|
506
|
+
* This allows us to distinguish reconnects to different
|
|
507
|
+
* transports.
|
|
508
|
+
*/
|
|
509
|
+
instanceId = (0, import_nanoid3.nanoid)();
|
|
510
|
+
connectedInstanceIds = /* @__PURE__ */ new Map();
|
|
499
511
|
/**
|
|
500
512
|
* A flag indicating whether the transport has been destroyed.
|
|
501
513
|
* A destroyed transport will not attempt to reconnect and cannot be used again.
|
|
@@ -557,12 +569,23 @@ var Transport = class {
|
|
|
557
569
|
* and we know the identity of the connected client.
|
|
558
570
|
* @param conn The connection object.
|
|
559
571
|
*/
|
|
560
|
-
onConnect(conn, connectedTo) {
|
|
572
|
+
onConnect(conn, connectedTo, instanceId) {
|
|
561
573
|
this.eventDispatcher.dispatchEvent("connectionStatus", {
|
|
562
574
|
status: "connect",
|
|
563
575
|
conn
|
|
564
576
|
});
|
|
565
|
-
|
|
577
|
+
let session = this.sessions.get(connectedTo);
|
|
578
|
+
const lastInstanceId = this.connectedInstanceIds.get(connectedTo);
|
|
579
|
+
if (session && lastInstanceId !== instanceId && lastInstanceId !== void 0) {
|
|
580
|
+
log?.warn(
|
|
581
|
+
`${this.clientId} -- handshake from ${connectedTo} has different server instance (got: ${instanceId}, last connected to: ${lastInstanceId}), starting a new session`
|
|
582
|
+
);
|
|
583
|
+
session.resetBufferedMessages();
|
|
584
|
+
session.closeStaleConnection(conn);
|
|
585
|
+
this.deleteSession(session);
|
|
586
|
+
session = void 0;
|
|
587
|
+
}
|
|
588
|
+
this.connectedInstanceIds.set(connectedTo, instanceId);
|
|
566
589
|
if (session === void 0) {
|
|
567
590
|
const newSession = this.createSession(connectedTo, conn);
|
|
568
591
|
log?.info(
|
|
@@ -593,13 +616,13 @@ var Transport = class {
|
|
|
593
616
|
}
|
|
594
617
|
deleteSession(session) {
|
|
595
618
|
this.sessions.delete(session.to);
|
|
619
|
+
log?.info(
|
|
620
|
+
`${this.clientId} -- session ${session.debugId} disconnect from ${session.to}`
|
|
621
|
+
);
|
|
596
622
|
this.eventDispatcher.dispatchEvent("sessionStatus", {
|
|
597
623
|
status: "disconnect",
|
|
598
624
|
session
|
|
599
625
|
});
|
|
600
|
-
log?.info(
|
|
601
|
-
`${this.clientId} -- session ${session.debugId} disconnect from ${session.to}`
|
|
602
|
-
);
|
|
603
626
|
}
|
|
604
627
|
/**
|
|
605
628
|
* The downstream implementation needs to call this when a connection is closed.
|
|
@@ -628,11 +651,13 @@ var Transport = class {
|
|
|
628
651
|
const parsedMsg = this.codec.fromBuffer(msg);
|
|
629
652
|
if (parsedMsg === null) {
|
|
630
653
|
const decodedBuffer = new TextDecoder().decode(msg);
|
|
631
|
-
log?.
|
|
654
|
+
log?.error(
|
|
655
|
+
`${this.clientId} -- received malformed msg, killing conn: ${decodedBuffer}`
|
|
656
|
+
);
|
|
632
657
|
return null;
|
|
633
658
|
}
|
|
634
659
|
if (!import_value.Value.Check(OpaqueTransportMessageSchema, parsedMsg)) {
|
|
635
|
-
log?.
|
|
660
|
+
log?.error(
|
|
636
661
|
`${this.clientId} -- received invalid msg: ${JSON.stringify(
|
|
637
662
|
parsedMsg
|
|
638
663
|
)}`
|
|
@@ -651,9 +676,6 @@ var Transport = class {
|
|
|
651
676
|
* @param msg The received message.
|
|
652
677
|
*/
|
|
653
678
|
handleMsg(msg) {
|
|
654
|
-
if (!msg) {
|
|
655
|
-
return;
|
|
656
|
-
}
|
|
657
679
|
const session = this.sessionByClientId(msg.from);
|
|
658
680
|
session.cancelGrace();
|
|
659
681
|
log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
|
|
@@ -755,7 +777,6 @@ var ClientTransport = class extends Transport {
|
|
|
755
777
|
*/
|
|
756
778
|
inflightConnectionPromises;
|
|
757
779
|
tryReconnecting = true;
|
|
758
|
-
serverInstanceIds = /* @__PURE__ */ new Map();
|
|
759
780
|
constructor(clientId, providedOptions) {
|
|
760
781
|
super(clientId, providedOptions);
|
|
761
782
|
this.inflightConnectionPromises = /* @__PURE__ */ new Map();
|
|
@@ -763,7 +784,14 @@ var ClientTransport = class extends Transport {
|
|
|
763
784
|
handleConnection(conn, to) {
|
|
764
785
|
const bootHandler = this.receiveWithBootSequence(conn, () => {
|
|
765
786
|
conn.removeDataListener(bootHandler);
|
|
766
|
-
conn.addDataListener((data) =>
|
|
787
|
+
conn.addDataListener((data) => {
|
|
788
|
+
const parsed = this.parseMsg(data);
|
|
789
|
+
if (!parsed) {
|
|
790
|
+
conn.close();
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
this.handleMsg(parsed);
|
|
794
|
+
});
|
|
767
795
|
});
|
|
768
796
|
conn.addDataListener(bootHandler);
|
|
769
797
|
conn.addCloseListener(() => {
|
|
@@ -795,7 +823,7 @@ var ClientTransport = class extends Transport {
|
|
|
795
823
|
try {
|
|
796
824
|
const conn = await reconnectPromise;
|
|
797
825
|
this.state = "open";
|
|
798
|
-
const requestMsg = bootRequestMessage(this.clientId, to);
|
|
826
|
+
const requestMsg = bootRequestMessage(this.clientId, to, this.instanceId);
|
|
799
827
|
log?.debug(`${this.clientId} -- sending boot handshake to ${to}`);
|
|
800
828
|
conn.send(this.codec.toBuffer(requestMsg));
|
|
801
829
|
} catch (error) {
|
|
@@ -818,8 +846,10 @@ var ClientTransport = class extends Transport {
|
|
|
818
846
|
receiveWithBootSequence(conn, sessionCb) {
|
|
819
847
|
const bootHandler = (data) => {
|
|
820
848
|
const parsed = this.parseMsg(data);
|
|
821
|
-
if (!parsed)
|
|
849
|
+
if (!parsed) {
|
|
850
|
+
conn.close();
|
|
822
851
|
return;
|
|
852
|
+
}
|
|
823
853
|
if (!import_value.Value.Check(ControlMessageHandshakeResponseSchema, parsed.payload)) {
|
|
824
854
|
log?.warn(
|
|
825
855
|
`${this.clientId} -- received invalid handshake resp: ${JSON.stringify(parsed)}`
|
|
@@ -834,22 +864,11 @@ var ClientTransport = class extends Transport {
|
|
|
834
864
|
);
|
|
835
865
|
return;
|
|
836
866
|
}
|
|
837
|
-
const oldSession = this.sessions.get(parsed.from);
|
|
838
867
|
const serverInstanceId = parsed.payload.status.instanceId;
|
|
839
|
-
const lastServerInstanceId = this.serverInstanceIds.get(parsed.from);
|
|
840
|
-
if (oldSession && lastServerInstanceId !== serverInstanceId && lastServerInstanceId !== void 0) {
|
|
841
|
-
log?.debug(
|
|
842
|
-
`${this.clientId} -- handshake from ${parsed.from} has different server instance (got: ${serverInstanceId}, last connected to: ${lastServerInstanceId}), starting a new session`
|
|
843
|
-
);
|
|
844
|
-
oldSession.resetBufferedMessages();
|
|
845
|
-
oldSession.closeStaleConnection();
|
|
846
|
-
this.deleteSession(oldSession);
|
|
847
|
-
}
|
|
848
868
|
log?.debug(
|
|
849
869
|
`${this.clientId} -- handshake from ${parsed.from} ok (server instance: ${serverInstanceId})`
|
|
850
870
|
);
|
|
851
|
-
this.
|
|
852
|
-
sessionCb(this.onConnect(conn, parsed.from));
|
|
871
|
+
sessionCb(this.onConnect(conn, parsed.from, serverInstanceId));
|
|
853
872
|
};
|
|
854
873
|
return bootHandler;
|
|
855
874
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-
|
|
2
|
-
import { U as UdsConnection } from '../../../connection-
|
|
1
|
+
import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-0c0a69f6.js';
|
|
2
|
+
import { U as UdsConnection } from '../../../connection-d880aa4a.js';
|
|
3
3
|
import '../../../types-3e5768ec.js';
|
|
4
4
|
import '@sinclair/typebox';
|
|
5
5
|
import 'node:net';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-
|
|
2
|
-
import { U as UdsConnection } from '../../../connection-
|
|
1
|
+
import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-0c0a69f6.js';
|
|
2
|
+
import { U as UdsConnection } from '../../../connection-d880aa4a.js';
|
|
3
3
|
import '../../../types-3e5768ec.js';
|
|
4
4
|
import '@sinclair/typebox';
|
|
5
5
|
import 'node:net';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UdsConnection
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-PIF32FUL.js";
|
|
4
4
|
import "../../../chunk-IIBVKYDB.js";
|
|
5
5
|
import {
|
|
6
6
|
ClientTransport
|
|
7
|
-
} from "../../../chunk-
|
|
7
|
+
} from "../../../chunk-CT57CKBS.js";
|
|
8
8
|
import "../../../chunk-GZ7HCLLM.js";
|
|
9
|
-
import "../../../chunk-
|
|
9
|
+
import "../../../chunk-XFFS4UOD.js";
|
|
10
10
|
import {
|
|
11
11
|
log
|
|
12
12
|
} from "../../../chunk-H4BYJELI.js";
|
|
@@ -54,7 +54,8 @@ var ControlMessageCloseSchema = import_typebox.Type.Object({
|
|
|
54
54
|
var PROTOCOL_VERSION = "v1";
|
|
55
55
|
var ControlMessageHandshakeRequestSchema = import_typebox.Type.Object({
|
|
56
56
|
type: import_typebox.Type.Literal("HANDSHAKE_REQ"),
|
|
57
|
-
protocolVersion: import_typebox.Type.Literal(PROTOCOL_VERSION)
|
|
57
|
+
protocolVersion: import_typebox.Type.Literal(PROTOCOL_VERSION),
|
|
58
|
+
instanceId: import_typebox.Type.String()
|
|
58
59
|
});
|
|
59
60
|
var ControlMessageHandshakeResponseSchema = import_typebox.Type.Object({
|
|
60
61
|
type: import_typebox.Type.Literal("HANDSHAKE_RESP"),
|
|
@@ -144,9 +145,9 @@ var Connection = class {
|
|
|
144
145
|
this.debugId = `conn-${unsafeId()}`;
|
|
145
146
|
}
|
|
146
147
|
};
|
|
147
|
-
var HEARTBEAT_INTERVAL_MS =
|
|
148
|
-
var HEARTBEATS_TILL_DEAD =
|
|
149
|
-
var SESSION_DISCONNECT_GRACE_MS =
|
|
148
|
+
var HEARTBEAT_INTERVAL_MS = 1e3;
|
|
149
|
+
var HEARTBEATS_TILL_DEAD = 2;
|
|
150
|
+
var SESSION_DISCONNECT_GRACE_MS = 5e3;
|
|
150
151
|
var Session = class {
|
|
151
152
|
codec;
|
|
152
153
|
/**
|
|
@@ -229,11 +230,13 @@ var Session = class {
|
|
|
229
230
|
return fullMsg.id;
|
|
230
231
|
}
|
|
231
232
|
sendHeartbeat() {
|
|
232
|
-
if (this.heartbeatMisses >= HEARTBEATS_TILL_DEAD
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
233
|
+
if (this.heartbeatMisses >= HEARTBEATS_TILL_DEAD) {
|
|
234
|
+
if (this.connection) {
|
|
235
|
+
log?.info(
|
|
236
|
+
`${this.from} -- closing connection (id: ${this.connection.debugId}) to ${this.to} due to inactivity`
|
|
237
|
+
);
|
|
238
|
+
this.closeStaleConnection(this.connection);
|
|
239
|
+
}
|
|
237
240
|
return;
|
|
238
241
|
}
|
|
239
242
|
this.send(
|
|
@@ -270,7 +273,6 @@ var Session = class {
|
|
|
270
273
|
}
|
|
271
274
|
}
|
|
272
275
|
updateBookkeeping(ack, seq) {
|
|
273
|
-
this.heartbeatMisses = 0;
|
|
274
276
|
this.sendBuffer = this.sendBuffer.filter((unacked) => unacked.seq > ack);
|
|
275
277
|
this.ack = seq + 1;
|
|
276
278
|
}
|
|
@@ -302,6 +304,7 @@ var Session = class {
|
|
|
302
304
|
}, SESSION_DISCONNECT_GRACE_MS);
|
|
303
305
|
}
|
|
304
306
|
cancelGrace() {
|
|
307
|
+
this.heartbeatMisses = 0;
|
|
305
308
|
clearTimeout(this.disconnectionGrace);
|
|
306
309
|
}
|
|
307
310
|
get connected() {
|
|
@@ -330,6 +333,7 @@ var Session = class {
|
|
|
330
333
|
*/
|
|
331
334
|
halfCloseConnection() {
|
|
332
335
|
this.connection?.close();
|
|
336
|
+
clearInterval(this.heartbeat);
|
|
333
337
|
}
|
|
334
338
|
inspectSendBuffer() {
|
|
335
339
|
return this.sendBuffer;
|
|
@@ -409,6 +413,13 @@ var defaultTransportOptions = {
|
|
|
409
413
|
codec: NaiveJsonCodec
|
|
410
414
|
};
|
|
411
415
|
var Transport = class {
|
|
416
|
+
/**
|
|
417
|
+
* Unique per instance of the transport.
|
|
418
|
+
* This allows us to distinguish reconnects to different
|
|
419
|
+
* transports.
|
|
420
|
+
*/
|
|
421
|
+
instanceId = (0, import_nanoid3.nanoid)();
|
|
422
|
+
connectedInstanceIds = /* @__PURE__ */ new Map();
|
|
412
423
|
/**
|
|
413
424
|
* A flag indicating whether the transport has been destroyed.
|
|
414
425
|
* A destroyed transport will not attempt to reconnect and cannot be used again.
|
|
@@ -470,12 +481,23 @@ var Transport = class {
|
|
|
470
481
|
* and we know the identity of the connected client.
|
|
471
482
|
* @param conn The connection object.
|
|
472
483
|
*/
|
|
473
|
-
onConnect(conn, connectedTo) {
|
|
484
|
+
onConnect(conn, connectedTo, instanceId) {
|
|
474
485
|
this.eventDispatcher.dispatchEvent("connectionStatus", {
|
|
475
486
|
status: "connect",
|
|
476
487
|
conn
|
|
477
488
|
});
|
|
478
|
-
|
|
489
|
+
let session = this.sessions.get(connectedTo);
|
|
490
|
+
const lastInstanceId = this.connectedInstanceIds.get(connectedTo);
|
|
491
|
+
if (session && lastInstanceId !== instanceId && lastInstanceId !== void 0) {
|
|
492
|
+
log?.warn(
|
|
493
|
+
`${this.clientId} -- handshake from ${connectedTo} has different server instance (got: ${instanceId}, last connected to: ${lastInstanceId}), starting a new session`
|
|
494
|
+
);
|
|
495
|
+
session.resetBufferedMessages();
|
|
496
|
+
session.closeStaleConnection(conn);
|
|
497
|
+
this.deleteSession(session);
|
|
498
|
+
session = void 0;
|
|
499
|
+
}
|
|
500
|
+
this.connectedInstanceIds.set(connectedTo, instanceId);
|
|
479
501
|
if (session === void 0) {
|
|
480
502
|
const newSession = this.createSession(connectedTo, conn);
|
|
481
503
|
log?.info(
|
|
@@ -506,13 +528,13 @@ var Transport = class {
|
|
|
506
528
|
}
|
|
507
529
|
deleteSession(session) {
|
|
508
530
|
this.sessions.delete(session.to);
|
|
531
|
+
log?.info(
|
|
532
|
+
`${this.clientId} -- session ${session.debugId} disconnect from ${session.to}`
|
|
533
|
+
);
|
|
509
534
|
this.eventDispatcher.dispatchEvent("sessionStatus", {
|
|
510
535
|
status: "disconnect",
|
|
511
536
|
session
|
|
512
537
|
});
|
|
513
|
-
log?.info(
|
|
514
|
-
`${this.clientId} -- session ${session.debugId} disconnect from ${session.to}`
|
|
515
|
-
);
|
|
516
538
|
}
|
|
517
539
|
/**
|
|
518
540
|
* The downstream implementation needs to call this when a connection is closed.
|
|
@@ -541,11 +563,13 @@ var Transport = class {
|
|
|
541
563
|
const parsedMsg = this.codec.fromBuffer(msg);
|
|
542
564
|
if (parsedMsg === null) {
|
|
543
565
|
const decodedBuffer = new TextDecoder().decode(msg);
|
|
544
|
-
log?.
|
|
566
|
+
log?.error(
|
|
567
|
+
`${this.clientId} -- received malformed msg, killing conn: ${decodedBuffer}`
|
|
568
|
+
);
|
|
545
569
|
return null;
|
|
546
570
|
}
|
|
547
571
|
if (!import_value.Value.Check(OpaqueTransportMessageSchema, parsedMsg)) {
|
|
548
|
-
log?.
|
|
572
|
+
log?.error(
|
|
549
573
|
`${this.clientId} -- received invalid msg: ${JSON.stringify(
|
|
550
574
|
parsedMsg
|
|
551
575
|
)}`
|
|
@@ -564,9 +588,6 @@ var Transport = class {
|
|
|
564
588
|
* @param msg The received message.
|
|
565
589
|
*/
|
|
566
590
|
handleMsg(msg) {
|
|
567
|
-
if (!msg) {
|
|
568
|
-
return;
|
|
569
|
-
}
|
|
570
591
|
const session = this.sessionByClientId(msg.from);
|
|
571
592
|
session.cancelGrace();
|
|
572
593
|
log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
|
|
@@ -663,14 +684,6 @@ var Transport = class {
|
|
|
663
684
|
}
|
|
664
685
|
};
|
|
665
686
|
var ServerTransport = class extends Transport {
|
|
666
|
-
/**
|
|
667
|
-
* Unique per instance of server transport.
|
|
668
|
-
* This allows us to distinguish reconnects to different
|
|
669
|
-
* server transports at the same reachable address and signal
|
|
670
|
-
* the appropriate session disconnect back to the client at the
|
|
671
|
-
* boot stage.
|
|
672
|
-
*/
|
|
673
|
-
instanceId = (0, import_nanoid3.nanoid)();
|
|
674
687
|
constructor(clientId, providedOptions) {
|
|
675
688
|
super(clientId, providedOptions);
|
|
676
689
|
log?.info(
|
|
@@ -685,7 +698,14 @@ var ServerTransport = class extends Transport {
|
|
|
685
698
|
(establishedSession) => {
|
|
686
699
|
session = establishedSession;
|
|
687
700
|
conn.removeDataListener(bootHandler);
|
|
688
|
-
conn.addDataListener((data) =>
|
|
701
|
+
conn.addDataListener((data) => {
|
|
702
|
+
const parsed = this.parseMsg(data);
|
|
703
|
+
if (!parsed) {
|
|
704
|
+
conn.close();
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
this.handleMsg(parsed);
|
|
708
|
+
});
|
|
689
709
|
}
|
|
690
710
|
);
|
|
691
711
|
conn.addDataListener(bootHandler);
|
|
@@ -708,8 +728,10 @@ var ServerTransport = class extends Transport {
|
|
|
708
728
|
receiveWithBootSequence(conn, sessionCb) {
|
|
709
729
|
const bootHandler = (data) => {
|
|
710
730
|
const parsed = this.parseMsg(data);
|
|
711
|
-
if (!parsed)
|
|
731
|
+
if (!parsed) {
|
|
732
|
+
conn.close();
|
|
712
733
|
return;
|
|
734
|
+
}
|
|
713
735
|
if (!import_value.Value.Check(ControlMessageHandshakeRequestSchema, parsed.payload)) {
|
|
714
736
|
const responseMsg2 = bootResponseMessage(
|
|
715
737
|
this.clientId,
|
|
@@ -725,8 +747,9 @@ var ServerTransport = class extends Transport {
|
|
|
725
747
|
);
|
|
726
748
|
return;
|
|
727
749
|
}
|
|
750
|
+
const instanceId = parsed.payload.instanceId;
|
|
728
751
|
log?.debug(
|
|
729
|
-
`${this.clientId} -- handshake from ${parsed.from} ok, responding with handshake success`
|
|
752
|
+
`${this.clientId} -- handshake from ${parsed.from} ok (instance id: ${instanceId}), responding with handshake success`
|
|
730
753
|
);
|
|
731
754
|
const responseMsg = bootResponseMessage(
|
|
732
755
|
this.clientId,
|
|
@@ -735,7 +758,7 @@ var ServerTransport = class extends Transport {
|
|
|
735
758
|
true
|
|
736
759
|
);
|
|
737
760
|
conn.send(this.codec.toBuffer(responseMsg));
|
|
738
|
-
sessionCb(this.onConnect(conn, parsed.from));
|
|
761
|
+
sessionCb(this.onConnect(conn, parsed.from, instanceId));
|
|
739
762
|
};
|
|
740
763
|
return bootHandler;
|
|
741
764
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Server, Socket } from 'node:net';
|
|
2
|
-
import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-
|
|
3
|
-
import { U as UdsConnection } from '../../../connection-
|
|
2
|
+
import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-0c0a69f6.js';
|
|
3
|
+
import { U as UdsConnection } from '../../../connection-d880aa4a.js';
|
|
4
4
|
import '../../../types-3e5768ec.js';
|
|
5
5
|
import '@sinclair/typebox';
|
|
6
6
|
import '../../../messageFraming-b200ef25.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Server, Socket } from 'node:net';
|
|
2
|
-
import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-
|
|
3
|
-
import { U as UdsConnection } from '../../../connection-
|
|
2
|
+
import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-0c0a69f6.js';
|
|
3
|
+
import { U as UdsConnection } from '../../../connection-d880aa4a.js';
|
|
4
4
|
import '../../../types-3e5768ec.js';
|
|
5
5
|
import '@sinclair/typebox';
|
|
6
6
|
import '../../../messageFraming-b200ef25.js';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UdsConnection
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-PIF32FUL.js";
|
|
4
4
|
import "../../../chunk-IIBVKYDB.js";
|
|
5
5
|
import {
|
|
6
6
|
ServerTransport
|
|
7
|
-
} from "../../../chunk-
|
|
7
|
+
} from "../../../chunk-CT57CKBS.js";
|
|
8
8
|
import "../../../chunk-GZ7HCLLM.js";
|
|
9
|
-
import "../../../chunk-
|
|
9
|
+
import "../../../chunk-XFFS4UOD.js";
|
|
10
10
|
import {
|
|
11
11
|
log
|
|
12
12
|
} from "../../../chunk-H4BYJELI.js";
|