@replit/river 0.12.1 → 0.12.3
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-QEYN2Z6O.js → chunk-2PKONGC3.js} +39 -35
- package/dist/{chunk-RDTTKCGV.js → chunk-6OAKPO5R.js} +1 -1
- package/dist/{chunk-TKINU53F.js → chunk-7J66WOIC.js} +1 -1
- package/dist/{chunk-55XUAPC6.js → chunk-AFLZ6INU.js} +1 -1
- package/dist/{chunk-M6LY25P2.js → chunk-H4QR2K3T.js} +1 -1
- package/dist/{connection-eb10d250.d.ts → connection-4a839b9a.d.ts} +1 -1
- package/dist/{connection-bf7811aa.d.ts → connection-64b9e0ff.d.ts} +1 -1
- package/dist/{connection-d880aa4a.d.ts → connection-a6cc48e8.d.ts} +1 -1
- package/dist/{index-0c0a69f6.d.ts → index-1afc5580.d.ts} +5 -9
- package/dist/router/index.cjs +1 -1
- package/dist/router/index.d.cts +1 -1
- package/dist/router/index.d.ts +1 -1
- package/dist/router/index.js +1 -1
- package/dist/transport/impls/stdio/client.cjs +39 -35
- 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 +2 -2
- package/dist/transport/impls/stdio/server.cjs +38 -33
- 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 +2 -2
- package/dist/transport/impls/uds/client.cjs +39 -35
- 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 +2 -2
- package/dist/transport/impls/uds/server.cjs +38 -33
- 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 +2 -2
- package/dist/transport/impls/ws/client.cjs +41 -36
- 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 +4 -3
- package/dist/transport/impls/ws/server.cjs +38 -33
- 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 +2 -2
- package/dist/transport/index.cjs +39 -35
- package/dist/transport/index.d.cts +1 -1
- package/dist/transport/index.d.ts +1 -1
- package/dist/transport/index.js +1 -1
- package/dist/util/testHelpers.d.cts +1 -1
- package/dist/util/testHelpers.d.ts +1 -1
- package/dist/util/testHelpers.js +1 -1
- package/package.json +1 -1
|
@@ -235,7 +235,7 @@ var Session = class {
|
|
|
235
235
|
log?.info(
|
|
236
236
|
`${this.from} -- closing connection (id: ${this.connection.debugId}) to ${this.to} due to inactivity`
|
|
237
237
|
);
|
|
238
|
-
this.
|
|
238
|
+
this.closeStaleConnection(this.connection);
|
|
239
239
|
}
|
|
240
240
|
return;
|
|
241
241
|
}
|
|
@@ -296,17 +296,27 @@ var Session = class {
|
|
|
296
296
|
this.cancelGrace();
|
|
297
297
|
this.connection = newConn;
|
|
298
298
|
}
|
|
299
|
+
graceCb;
|
|
299
300
|
beginGrace(cb) {
|
|
301
|
+
this.graceCb = cb;
|
|
300
302
|
this.disconnectionGrace = setTimeout(() => {
|
|
301
|
-
this.
|
|
302
|
-
clearInterval(this.heartbeat);
|
|
303
|
+
this.close();
|
|
303
304
|
cb();
|
|
304
305
|
}, SESSION_DISCONNECT_GRACE_MS);
|
|
305
306
|
}
|
|
307
|
+
// called on reconnect of the underlying session
|
|
306
308
|
cancelGrace() {
|
|
307
309
|
this.heartbeatMisses = 0;
|
|
308
310
|
clearTimeout(this.disconnectionGrace);
|
|
309
311
|
}
|
|
312
|
+
// closed when we want to discard the whole session
|
|
313
|
+
// (i.e. shutdown or session disconnect)
|
|
314
|
+
close() {
|
|
315
|
+
this.closeStaleConnection(this.connection);
|
|
316
|
+
this.cancelGrace();
|
|
317
|
+
clearInterval(this.heartbeat);
|
|
318
|
+
this.resetBufferedMessages();
|
|
319
|
+
}
|
|
310
320
|
get connected() {
|
|
311
321
|
return this.connection !== void 0;
|
|
312
322
|
}
|
|
@@ -325,15 +335,6 @@ var Session = class {
|
|
|
325
335
|
this.seq++;
|
|
326
336
|
return msg;
|
|
327
337
|
}
|
|
328
|
-
/**
|
|
329
|
-
* Closes the out-going connection but doesn't remove the listeners
|
|
330
|
-
* for incoming messages. The connection will eventually call onClose
|
|
331
|
-
* when it is ready to be cleaned up and only then will {@link connection} be set back
|
|
332
|
-
* to undefined
|
|
333
|
-
*/
|
|
334
|
-
halfCloseConnection() {
|
|
335
|
-
this.connection?.close();
|
|
336
|
-
}
|
|
337
338
|
inspectSendBuffer() {
|
|
338
339
|
return this.sendBuffer;
|
|
339
340
|
}
|
|
@@ -485,19 +486,18 @@ var Transport = class {
|
|
|
485
486
|
status: "connect",
|
|
486
487
|
conn
|
|
487
488
|
});
|
|
488
|
-
let
|
|
489
|
+
let oldSession = this.sessions.get(connectedTo);
|
|
489
490
|
const lastInstanceId = this.connectedInstanceIds.get(connectedTo);
|
|
490
|
-
if (
|
|
491
|
-
log?.
|
|
492
|
-
`${this.clientId} -- handshake from ${connectedTo}
|
|
491
|
+
if (oldSession && lastInstanceId !== void 0 && lastInstanceId !== instanceId) {
|
|
492
|
+
log?.warn(
|
|
493
|
+
`${this.clientId} -- handshake from ${connectedTo} is a different instance (got: ${instanceId}, last connected to: ${lastInstanceId}), starting a new session`
|
|
493
494
|
);
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
session = void 0;
|
|
495
|
+
oldSession.close();
|
|
496
|
+
this.deleteSession(oldSession);
|
|
497
|
+
oldSession = void 0;
|
|
498
498
|
}
|
|
499
499
|
this.connectedInstanceIds.set(connectedTo, instanceId);
|
|
500
|
-
if (
|
|
500
|
+
if (oldSession === void 0) {
|
|
501
501
|
const newSession = this.createSession(connectedTo, conn);
|
|
502
502
|
log?.info(
|
|
503
503
|
`${this.clientId} -- new connection (id: ${conn.debugId}) for new session (id: ${newSession.debugId}) to ${connectedTo}`
|
|
@@ -505,11 +505,11 @@ var Transport = class {
|
|
|
505
505
|
return newSession;
|
|
506
506
|
}
|
|
507
507
|
log?.info(
|
|
508
|
-
`${this.clientId} -- new connection (id: ${conn.debugId}) for existing session (id: ${
|
|
508
|
+
`${this.clientId} -- new connection (id: ${conn.debugId}) for existing session (id: ${oldSession.debugId}) to ${connectedTo}`
|
|
509
509
|
);
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
return
|
|
510
|
+
oldSession.replaceWithNewConnection(conn);
|
|
511
|
+
oldSession.sendBufferedMessages();
|
|
512
|
+
return oldSession;
|
|
513
513
|
}
|
|
514
514
|
createSession(connectedTo, conn) {
|
|
515
515
|
const session = new Session(
|
|
@@ -527,24 +527,25 @@ var Transport = class {
|
|
|
527
527
|
}
|
|
528
528
|
deleteSession(session) {
|
|
529
529
|
this.sessions.delete(session.to);
|
|
530
|
+
log?.info(
|
|
531
|
+
`${this.clientId} -- session ${session.debugId} disconnect from ${session.to}`
|
|
532
|
+
);
|
|
530
533
|
this.eventDispatcher.dispatchEvent("sessionStatus", {
|
|
531
534
|
status: "disconnect",
|
|
532
535
|
session
|
|
533
536
|
});
|
|
534
|
-
log?.info(
|
|
535
|
-
`${this.clientId} -- session ${session.debugId} disconnect from ${session.to}`
|
|
536
|
-
);
|
|
537
537
|
}
|
|
538
538
|
/**
|
|
539
539
|
* The downstream implementation needs to call this when a connection is closed.
|
|
540
540
|
* @param conn The connection object.
|
|
541
|
+
* @param connectedTo The peer we are connected to.
|
|
541
542
|
*/
|
|
542
543
|
onDisconnect(conn, connectedTo) {
|
|
543
544
|
this.eventDispatcher.dispatchEvent("connectionStatus", {
|
|
544
545
|
status: "disconnect",
|
|
545
546
|
conn
|
|
546
547
|
});
|
|
547
|
-
if (
|
|
548
|
+
if (this.state !== "open")
|
|
548
549
|
return;
|
|
549
550
|
const session = this.sessionByClientId(connectedTo);
|
|
550
551
|
log?.info(
|
|
@@ -587,6 +588,8 @@ var Transport = class {
|
|
|
587
588
|
* @param msg The received message.
|
|
588
589
|
*/
|
|
589
590
|
handleMsg(msg) {
|
|
591
|
+
if (this.state !== "open")
|
|
592
|
+
return;
|
|
590
593
|
const session = this.sessionByClientId(msg.from);
|
|
591
594
|
session.cancelGrace();
|
|
592
595
|
log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
|
|
@@ -663,10 +666,11 @@ var Transport = class {
|
|
|
663
666
|
* Closes the transport. Any messages sent while the transport is closed will be silently discarded.
|
|
664
667
|
*/
|
|
665
668
|
close() {
|
|
669
|
+
this.state = "closed";
|
|
666
670
|
for (const session of this.sessions.values()) {
|
|
667
|
-
session.
|
|
671
|
+
session.close();
|
|
672
|
+
this.deleteSession(session);
|
|
668
673
|
}
|
|
669
|
-
this.state = "closed";
|
|
670
674
|
log?.info(`${this.clientId} -- manually closed transport`);
|
|
671
675
|
}
|
|
672
676
|
/**
|
|
@@ -675,10 +679,11 @@ var Transport = class {
|
|
|
675
679
|
* Destroys the transport. Any messages sent while the transport is destroyed will throw an error.
|
|
676
680
|
*/
|
|
677
681
|
destroy() {
|
|
682
|
+
this.state = "destroyed";
|
|
678
683
|
for (const session of this.sessions.values()) {
|
|
679
|
-
session.
|
|
684
|
+
session.close();
|
|
685
|
+
this.deleteSession(session);
|
|
680
686
|
}
|
|
681
|
-
this.state = "destroyed";
|
|
682
687
|
log?.info(`${this.clientId} -- manually destroyed transport`);
|
|
683
688
|
}
|
|
684
689
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-
|
|
2
|
-
import { S as StreamConnection } from '../../../connection-
|
|
1
|
+
import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-1afc5580.js';
|
|
2
|
+
import { S as StreamConnection } from '../../../connection-64b9e0ff.js';
|
|
3
3
|
import '../../../types-3e5768ec.js';
|
|
4
4
|
import '@sinclair/typebox';
|
|
5
5
|
import '../../../messageFraming-b200ef25.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-
|
|
2
|
-
import { S as StreamConnection } from '../../../connection-
|
|
1
|
+
import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-1afc5580.js';
|
|
2
|
+
import { S as StreamConnection } from '../../../connection-64b9e0ff.js';
|
|
3
3
|
import '../../../types-3e5768ec.js';
|
|
4
4
|
import '@sinclair/typebox';
|
|
5
5
|
import '../../../messageFraming-b200ef25.js';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
StreamConnection
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-H4QR2K3T.js";
|
|
4
4
|
import "../../../chunk-5IZ2UHWV.js";
|
|
5
5
|
import "../../../chunk-IIBVKYDB.js";
|
|
6
6
|
import {
|
|
7
7
|
ServerTransport
|
|
8
|
-
} from "../../../chunk-
|
|
8
|
+
} from "../../../chunk-2PKONGC3.js";
|
|
9
9
|
import "../../../chunk-GZ7HCLLM.js";
|
|
10
10
|
import "../../../chunk-XFFS4UOD.js";
|
|
11
11
|
import "../../../chunk-H4BYJELI.js";
|
|
@@ -199,7 +199,7 @@ var Session = class {
|
|
|
199
199
|
log?.info(
|
|
200
200
|
`${this.from} -- closing connection (id: ${this.connection.debugId}) to ${this.to} due to inactivity`
|
|
201
201
|
);
|
|
202
|
-
this.
|
|
202
|
+
this.closeStaleConnection(this.connection);
|
|
203
203
|
}
|
|
204
204
|
return;
|
|
205
205
|
}
|
|
@@ -260,17 +260,27 @@ var Session = class {
|
|
|
260
260
|
this.cancelGrace();
|
|
261
261
|
this.connection = newConn;
|
|
262
262
|
}
|
|
263
|
+
graceCb;
|
|
263
264
|
beginGrace(cb) {
|
|
265
|
+
this.graceCb = cb;
|
|
264
266
|
this.disconnectionGrace = setTimeout(() => {
|
|
265
|
-
this.
|
|
266
|
-
clearInterval(this.heartbeat);
|
|
267
|
+
this.close();
|
|
267
268
|
cb();
|
|
268
269
|
}, SESSION_DISCONNECT_GRACE_MS);
|
|
269
270
|
}
|
|
271
|
+
// called on reconnect of the underlying session
|
|
270
272
|
cancelGrace() {
|
|
271
273
|
this.heartbeatMisses = 0;
|
|
272
274
|
clearTimeout(this.disconnectionGrace);
|
|
273
275
|
}
|
|
276
|
+
// closed when we want to discard the whole session
|
|
277
|
+
// (i.e. shutdown or session disconnect)
|
|
278
|
+
close() {
|
|
279
|
+
this.closeStaleConnection(this.connection);
|
|
280
|
+
this.cancelGrace();
|
|
281
|
+
clearInterval(this.heartbeat);
|
|
282
|
+
this.resetBufferedMessages();
|
|
283
|
+
}
|
|
274
284
|
get connected() {
|
|
275
285
|
return this.connection !== void 0;
|
|
276
286
|
}
|
|
@@ -289,15 +299,6 @@ var Session = class {
|
|
|
289
299
|
this.seq++;
|
|
290
300
|
return msg;
|
|
291
301
|
}
|
|
292
|
-
/**
|
|
293
|
-
* Closes the out-going connection but doesn't remove the listeners
|
|
294
|
-
* for incoming messages. The connection will eventually call onClose
|
|
295
|
-
* when it is ready to be cleaned up and only then will {@link connection} be set back
|
|
296
|
-
* to undefined
|
|
297
|
-
*/
|
|
298
|
-
halfCloseConnection() {
|
|
299
|
-
this.connection?.close();
|
|
300
|
-
}
|
|
301
302
|
inspectSendBuffer() {
|
|
302
303
|
return this.sendBuffer;
|
|
303
304
|
}
|
|
@@ -573,19 +574,18 @@ var Transport = class {
|
|
|
573
574
|
status: "connect",
|
|
574
575
|
conn
|
|
575
576
|
});
|
|
576
|
-
let
|
|
577
|
+
let oldSession = this.sessions.get(connectedTo);
|
|
577
578
|
const lastInstanceId = this.connectedInstanceIds.get(connectedTo);
|
|
578
|
-
if (
|
|
579
|
-
log?.
|
|
580
|
-
`${this.clientId} -- handshake from ${connectedTo}
|
|
579
|
+
if (oldSession && lastInstanceId !== void 0 && lastInstanceId !== instanceId) {
|
|
580
|
+
log?.warn(
|
|
581
|
+
`${this.clientId} -- handshake from ${connectedTo} is a different instance (got: ${instanceId}, last connected to: ${lastInstanceId}), starting a new session`
|
|
581
582
|
);
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
session = void 0;
|
|
583
|
+
oldSession.close();
|
|
584
|
+
this.deleteSession(oldSession);
|
|
585
|
+
oldSession = void 0;
|
|
586
586
|
}
|
|
587
587
|
this.connectedInstanceIds.set(connectedTo, instanceId);
|
|
588
|
-
if (
|
|
588
|
+
if (oldSession === void 0) {
|
|
589
589
|
const newSession = this.createSession(connectedTo, conn);
|
|
590
590
|
log?.info(
|
|
591
591
|
`${this.clientId} -- new connection (id: ${conn.debugId}) for new session (id: ${newSession.debugId}) to ${connectedTo}`
|
|
@@ -593,11 +593,11 @@ var Transport = class {
|
|
|
593
593
|
return newSession;
|
|
594
594
|
}
|
|
595
595
|
log?.info(
|
|
596
|
-
`${this.clientId} -- new connection (id: ${conn.debugId}) for existing session (id: ${
|
|
596
|
+
`${this.clientId} -- new connection (id: ${conn.debugId}) for existing session (id: ${oldSession.debugId}) to ${connectedTo}`
|
|
597
597
|
);
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
return
|
|
598
|
+
oldSession.replaceWithNewConnection(conn);
|
|
599
|
+
oldSession.sendBufferedMessages();
|
|
600
|
+
return oldSession;
|
|
601
601
|
}
|
|
602
602
|
createSession(connectedTo, conn) {
|
|
603
603
|
const session = new Session(
|
|
@@ -615,24 +615,25 @@ var Transport = class {
|
|
|
615
615
|
}
|
|
616
616
|
deleteSession(session) {
|
|
617
617
|
this.sessions.delete(session.to);
|
|
618
|
+
log?.info(
|
|
619
|
+
`${this.clientId} -- session ${session.debugId} disconnect from ${session.to}`
|
|
620
|
+
);
|
|
618
621
|
this.eventDispatcher.dispatchEvent("sessionStatus", {
|
|
619
622
|
status: "disconnect",
|
|
620
623
|
session
|
|
621
624
|
});
|
|
622
|
-
log?.info(
|
|
623
|
-
`${this.clientId} -- session ${session.debugId} disconnect from ${session.to}`
|
|
624
|
-
);
|
|
625
625
|
}
|
|
626
626
|
/**
|
|
627
627
|
* The downstream implementation needs to call this when a connection is closed.
|
|
628
628
|
* @param conn The connection object.
|
|
629
|
+
* @param connectedTo The peer we are connected to.
|
|
629
630
|
*/
|
|
630
631
|
onDisconnect(conn, connectedTo) {
|
|
631
632
|
this.eventDispatcher.dispatchEvent("connectionStatus", {
|
|
632
633
|
status: "disconnect",
|
|
633
634
|
conn
|
|
634
635
|
});
|
|
635
|
-
if (
|
|
636
|
+
if (this.state !== "open")
|
|
636
637
|
return;
|
|
637
638
|
const session = this.sessionByClientId(connectedTo);
|
|
638
639
|
log?.info(
|
|
@@ -675,6 +676,8 @@ var Transport = class {
|
|
|
675
676
|
* @param msg The received message.
|
|
676
677
|
*/
|
|
677
678
|
handleMsg(msg) {
|
|
679
|
+
if (this.state !== "open")
|
|
680
|
+
return;
|
|
678
681
|
const session = this.sessionByClientId(msg.from);
|
|
679
682
|
session.cancelGrace();
|
|
680
683
|
log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
|
|
@@ -751,10 +754,11 @@ var Transport = class {
|
|
|
751
754
|
* Closes the transport. Any messages sent while the transport is closed will be silently discarded.
|
|
752
755
|
*/
|
|
753
756
|
close() {
|
|
757
|
+
this.state = "closed";
|
|
754
758
|
for (const session of this.sessions.values()) {
|
|
755
|
-
session.
|
|
759
|
+
session.close();
|
|
760
|
+
this.deleteSession(session);
|
|
756
761
|
}
|
|
757
|
-
this.state = "closed";
|
|
758
762
|
log?.info(`${this.clientId} -- manually closed transport`);
|
|
759
763
|
}
|
|
760
764
|
/**
|
|
@@ -763,10 +767,11 @@ var Transport = class {
|
|
|
763
767
|
* Destroys the transport. Any messages sent while the transport is destroyed will throw an error.
|
|
764
768
|
*/
|
|
765
769
|
destroy() {
|
|
770
|
+
this.state = "destroyed";
|
|
766
771
|
for (const session of this.sessions.values()) {
|
|
767
|
-
session.
|
|
772
|
+
session.close();
|
|
773
|
+
this.deleteSession(session);
|
|
768
774
|
}
|
|
769
|
-
this.state = "destroyed";
|
|
770
775
|
log?.info(`${this.clientId} -- manually destroyed transport`);
|
|
771
776
|
}
|
|
772
777
|
};
|
|
@@ -872,8 +877,7 @@ var ClientTransport = class extends Transport {
|
|
|
872
877
|
return bootHandler;
|
|
873
878
|
}
|
|
874
879
|
onDisconnect(conn, connectedTo) {
|
|
875
|
-
|
|
876
|
-
this.inflightConnectionPromises.delete(connectedTo);
|
|
880
|
+
this.inflightConnectionPromises.delete(connectedTo);
|
|
877
881
|
super.onDisconnect(conn, connectedTo);
|
|
878
882
|
}
|
|
879
883
|
};
|
|
@@ -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-1afc5580.js';
|
|
2
|
+
import { U as UdsConnection } from '../../../connection-a6cc48e8.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-1afc5580.js';
|
|
2
|
+
import { U as UdsConnection } from '../../../connection-a6cc48e8.js';
|
|
3
3
|
import '../../../types-3e5768ec.js';
|
|
4
4
|
import '@sinclair/typebox';
|
|
5
5
|
import 'node:net';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UdsConnection
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-7J66WOIC.js";
|
|
4
4
|
import "../../../chunk-IIBVKYDB.js";
|
|
5
5
|
import {
|
|
6
6
|
ClientTransport
|
|
7
|
-
} from "../../../chunk-
|
|
7
|
+
} from "../../../chunk-2PKONGC3.js";
|
|
8
8
|
import "../../../chunk-GZ7HCLLM.js";
|
|
9
9
|
import "../../../chunk-XFFS4UOD.js";
|
|
10
10
|
import {
|
|
@@ -235,7 +235,7 @@ var Session = class {
|
|
|
235
235
|
log?.info(
|
|
236
236
|
`${this.from} -- closing connection (id: ${this.connection.debugId}) to ${this.to} due to inactivity`
|
|
237
237
|
);
|
|
238
|
-
this.
|
|
238
|
+
this.closeStaleConnection(this.connection);
|
|
239
239
|
}
|
|
240
240
|
return;
|
|
241
241
|
}
|
|
@@ -296,17 +296,27 @@ var Session = class {
|
|
|
296
296
|
this.cancelGrace();
|
|
297
297
|
this.connection = newConn;
|
|
298
298
|
}
|
|
299
|
+
graceCb;
|
|
299
300
|
beginGrace(cb) {
|
|
301
|
+
this.graceCb = cb;
|
|
300
302
|
this.disconnectionGrace = setTimeout(() => {
|
|
301
|
-
this.
|
|
302
|
-
clearInterval(this.heartbeat);
|
|
303
|
+
this.close();
|
|
303
304
|
cb();
|
|
304
305
|
}, SESSION_DISCONNECT_GRACE_MS);
|
|
305
306
|
}
|
|
307
|
+
// called on reconnect of the underlying session
|
|
306
308
|
cancelGrace() {
|
|
307
309
|
this.heartbeatMisses = 0;
|
|
308
310
|
clearTimeout(this.disconnectionGrace);
|
|
309
311
|
}
|
|
312
|
+
// closed when we want to discard the whole session
|
|
313
|
+
// (i.e. shutdown or session disconnect)
|
|
314
|
+
close() {
|
|
315
|
+
this.closeStaleConnection(this.connection);
|
|
316
|
+
this.cancelGrace();
|
|
317
|
+
clearInterval(this.heartbeat);
|
|
318
|
+
this.resetBufferedMessages();
|
|
319
|
+
}
|
|
310
320
|
get connected() {
|
|
311
321
|
return this.connection !== void 0;
|
|
312
322
|
}
|
|
@@ -325,15 +335,6 @@ var Session = class {
|
|
|
325
335
|
this.seq++;
|
|
326
336
|
return msg;
|
|
327
337
|
}
|
|
328
|
-
/**
|
|
329
|
-
* Closes the out-going connection but doesn't remove the listeners
|
|
330
|
-
* for incoming messages. The connection will eventually call onClose
|
|
331
|
-
* when it is ready to be cleaned up and only then will {@link connection} be set back
|
|
332
|
-
* to undefined
|
|
333
|
-
*/
|
|
334
|
-
halfCloseConnection() {
|
|
335
|
-
this.connection?.close();
|
|
336
|
-
}
|
|
337
338
|
inspectSendBuffer() {
|
|
338
339
|
return this.sendBuffer;
|
|
339
340
|
}
|
|
@@ -485,19 +486,18 @@ var Transport = class {
|
|
|
485
486
|
status: "connect",
|
|
486
487
|
conn
|
|
487
488
|
});
|
|
488
|
-
let
|
|
489
|
+
let oldSession = this.sessions.get(connectedTo);
|
|
489
490
|
const lastInstanceId = this.connectedInstanceIds.get(connectedTo);
|
|
490
|
-
if (
|
|
491
|
-
log?.
|
|
492
|
-
`${this.clientId} -- handshake from ${connectedTo}
|
|
491
|
+
if (oldSession && lastInstanceId !== void 0 && lastInstanceId !== instanceId) {
|
|
492
|
+
log?.warn(
|
|
493
|
+
`${this.clientId} -- handshake from ${connectedTo} is a different instance (got: ${instanceId}, last connected to: ${lastInstanceId}), starting a new session`
|
|
493
494
|
);
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
session = void 0;
|
|
495
|
+
oldSession.close();
|
|
496
|
+
this.deleteSession(oldSession);
|
|
497
|
+
oldSession = void 0;
|
|
498
498
|
}
|
|
499
499
|
this.connectedInstanceIds.set(connectedTo, instanceId);
|
|
500
|
-
if (
|
|
500
|
+
if (oldSession === void 0) {
|
|
501
501
|
const newSession = this.createSession(connectedTo, conn);
|
|
502
502
|
log?.info(
|
|
503
503
|
`${this.clientId} -- new connection (id: ${conn.debugId}) for new session (id: ${newSession.debugId}) to ${connectedTo}`
|
|
@@ -505,11 +505,11 @@ var Transport = class {
|
|
|
505
505
|
return newSession;
|
|
506
506
|
}
|
|
507
507
|
log?.info(
|
|
508
|
-
`${this.clientId} -- new connection (id: ${conn.debugId}) for existing session (id: ${
|
|
508
|
+
`${this.clientId} -- new connection (id: ${conn.debugId}) for existing session (id: ${oldSession.debugId}) to ${connectedTo}`
|
|
509
509
|
);
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
return
|
|
510
|
+
oldSession.replaceWithNewConnection(conn);
|
|
511
|
+
oldSession.sendBufferedMessages();
|
|
512
|
+
return oldSession;
|
|
513
513
|
}
|
|
514
514
|
createSession(connectedTo, conn) {
|
|
515
515
|
const session = new Session(
|
|
@@ -527,24 +527,25 @@ var Transport = class {
|
|
|
527
527
|
}
|
|
528
528
|
deleteSession(session) {
|
|
529
529
|
this.sessions.delete(session.to);
|
|
530
|
+
log?.info(
|
|
531
|
+
`${this.clientId} -- session ${session.debugId} disconnect from ${session.to}`
|
|
532
|
+
);
|
|
530
533
|
this.eventDispatcher.dispatchEvent("sessionStatus", {
|
|
531
534
|
status: "disconnect",
|
|
532
535
|
session
|
|
533
536
|
});
|
|
534
|
-
log?.info(
|
|
535
|
-
`${this.clientId} -- session ${session.debugId} disconnect from ${session.to}`
|
|
536
|
-
);
|
|
537
537
|
}
|
|
538
538
|
/**
|
|
539
539
|
* The downstream implementation needs to call this when a connection is closed.
|
|
540
540
|
* @param conn The connection object.
|
|
541
|
+
* @param connectedTo The peer we are connected to.
|
|
541
542
|
*/
|
|
542
543
|
onDisconnect(conn, connectedTo) {
|
|
543
544
|
this.eventDispatcher.dispatchEvent("connectionStatus", {
|
|
544
545
|
status: "disconnect",
|
|
545
546
|
conn
|
|
546
547
|
});
|
|
547
|
-
if (
|
|
548
|
+
if (this.state !== "open")
|
|
548
549
|
return;
|
|
549
550
|
const session = this.sessionByClientId(connectedTo);
|
|
550
551
|
log?.info(
|
|
@@ -587,6 +588,8 @@ var Transport = class {
|
|
|
587
588
|
* @param msg The received message.
|
|
588
589
|
*/
|
|
589
590
|
handleMsg(msg) {
|
|
591
|
+
if (this.state !== "open")
|
|
592
|
+
return;
|
|
590
593
|
const session = this.sessionByClientId(msg.from);
|
|
591
594
|
session.cancelGrace();
|
|
592
595
|
log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
|
|
@@ -663,10 +666,11 @@ var Transport = class {
|
|
|
663
666
|
* Closes the transport. Any messages sent while the transport is closed will be silently discarded.
|
|
664
667
|
*/
|
|
665
668
|
close() {
|
|
669
|
+
this.state = "closed";
|
|
666
670
|
for (const session of this.sessions.values()) {
|
|
667
|
-
session.
|
|
671
|
+
session.close();
|
|
672
|
+
this.deleteSession(session);
|
|
668
673
|
}
|
|
669
|
-
this.state = "closed";
|
|
670
674
|
log?.info(`${this.clientId} -- manually closed transport`);
|
|
671
675
|
}
|
|
672
676
|
/**
|
|
@@ -675,10 +679,11 @@ var Transport = class {
|
|
|
675
679
|
* Destroys the transport. Any messages sent while the transport is destroyed will throw an error.
|
|
676
680
|
*/
|
|
677
681
|
destroy() {
|
|
682
|
+
this.state = "destroyed";
|
|
678
683
|
for (const session of this.sessions.values()) {
|
|
679
|
-
session.
|
|
684
|
+
session.close();
|
|
685
|
+
this.deleteSession(session);
|
|
680
686
|
}
|
|
681
|
-
this.state = "destroyed";
|
|
682
687
|
log?.info(`${this.clientId} -- manually destroyed transport`);
|
|
683
688
|
}
|
|
684
689
|
};
|
|
@@ -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-1afc5580.js';
|
|
3
|
+
import { U as UdsConnection } from '../../../connection-a6cc48e8.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-1afc5580.js';
|
|
3
|
+
import { U as UdsConnection } from '../../../connection-a6cc48e8.js';
|
|
4
4
|
import '../../../types-3e5768ec.js';
|
|
5
5
|
import '@sinclair/typebox';
|
|
6
6
|
import '../../../messageFraming-b200ef25.js';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UdsConnection
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-7J66WOIC.js";
|
|
4
4
|
import "../../../chunk-IIBVKYDB.js";
|
|
5
5
|
import {
|
|
6
6
|
ServerTransport
|
|
7
|
-
} from "../../../chunk-
|
|
7
|
+
} from "../../../chunk-2PKONGC3.js";
|
|
8
8
|
import "../../../chunk-GZ7HCLLM.js";
|
|
9
9
|
import "../../../chunk-XFFS4UOD.js";
|
|
10
10
|
import {
|