@replit/river 0.12.2 → 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-CT57CKBS.js → chunk-2PKONGC3.js} +34 -31
- package/dist/{chunk-NHSJ4RDY.js → chunk-6OAKPO5R.js} +1 -1
- package/dist/{chunk-PIF32FUL.js → chunk-7J66WOIC.js} +1 -1
- package/dist/{chunk-55XUAPC6.js → chunk-AFLZ6INU.js} +1 -1
- package/dist/{chunk-R6YJHJV7.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 +34 -31
- 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 +33 -29
- 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 +34 -31
- 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 +33 -29
- 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 +36 -32
- 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 +33 -29
- 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 +34 -31
- 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
|
@@ -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,16 +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
|
-
clearInterval(this.heartbeat);
|
|
301
|
-
}
|
|
302
302
|
inspectSendBuffer() {
|
|
303
303
|
return this.sendBuffer;
|
|
304
304
|
}
|
|
@@ -574,19 +574,18 @@ var Transport = class {
|
|
|
574
574
|
status: "connect",
|
|
575
575
|
conn
|
|
576
576
|
});
|
|
577
|
-
let
|
|
577
|
+
let oldSession = this.sessions.get(connectedTo);
|
|
578
578
|
const lastInstanceId = this.connectedInstanceIds.get(connectedTo);
|
|
579
|
-
if (
|
|
579
|
+
if (oldSession && lastInstanceId !== void 0 && lastInstanceId !== instanceId) {
|
|
580
580
|
log?.warn(
|
|
581
|
-
`${this.clientId} -- handshake from ${connectedTo}
|
|
581
|
+
`${this.clientId} -- handshake from ${connectedTo} is a different instance (got: ${instanceId}, last connected to: ${lastInstanceId}), starting a new session`
|
|
582
582
|
);
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
session = void 0;
|
|
583
|
+
oldSession.close();
|
|
584
|
+
this.deleteSession(oldSession);
|
|
585
|
+
oldSession = void 0;
|
|
587
586
|
}
|
|
588
587
|
this.connectedInstanceIds.set(connectedTo, instanceId);
|
|
589
|
-
if (
|
|
588
|
+
if (oldSession === void 0) {
|
|
590
589
|
const newSession = this.createSession(connectedTo, conn);
|
|
591
590
|
log?.info(
|
|
592
591
|
`${this.clientId} -- new connection (id: ${conn.debugId}) for new session (id: ${newSession.debugId}) to ${connectedTo}`
|
|
@@ -594,11 +593,11 @@ var Transport = class {
|
|
|
594
593
|
return newSession;
|
|
595
594
|
}
|
|
596
595
|
log?.info(
|
|
597
|
-
`${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}`
|
|
598
597
|
);
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
return
|
|
598
|
+
oldSession.replaceWithNewConnection(conn);
|
|
599
|
+
oldSession.sendBufferedMessages();
|
|
600
|
+
return oldSession;
|
|
602
601
|
}
|
|
603
602
|
createSession(connectedTo, conn) {
|
|
604
603
|
const session = new Session(
|
|
@@ -627,13 +626,14 @@ var Transport = class {
|
|
|
627
626
|
/**
|
|
628
627
|
* The downstream implementation needs to call this when a connection is closed.
|
|
629
628
|
* @param conn The connection object.
|
|
629
|
+
* @param connectedTo The peer we are connected to.
|
|
630
630
|
*/
|
|
631
631
|
onDisconnect(conn, connectedTo) {
|
|
632
632
|
this.eventDispatcher.dispatchEvent("connectionStatus", {
|
|
633
633
|
status: "disconnect",
|
|
634
634
|
conn
|
|
635
635
|
});
|
|
636
|
-
if (
|
|
636
|
+
if (this.state !== "open")
|
|
637
637
|
return;
|
|
638
638
|
const session = this.sessionByClientId(connectedTo);
|
|
639
639
|
log?.info(
|
|
@@ -676,6 +676,8 @@ var Transport = class {
|
|
|
676
676
|
* @param msg The received message.
|
|
677
677
|
*/
|
|
678
678
|
handleMsg(msg) {
|
|
679
|
+
if (this.state !== "open")
|
|
680
|
+
return;
|
|
679
681
|
const session = this.sessionByClientId(msg.from);
|
|
680
682
|
session.cancelGrace();
|
|
681
683
|
log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
|
|
@@ -752,10 +754,11 @@ var Transport = class {
|
|
|
752
754
|
* Closes the transport. Any messages sent while the transport is closed will be silently discarded.
|
|
753
755
|
*/
|
|
754
756
|
close() {
|
|
757
|
+
this.state = "closed";
|
|
755
758
|
for (const session of this.sessions.values()) {
|
|
756
|
-
session.
|
|
759
|
+
session.close();
|
|
760
|
+
this.deleteSession(session);
|
|
757
761
|
}
|
|
758
|
-
this.state = "closed";
|
|
759
762
|
log?.info(`${this.clientId} -- manually closed transport`);
|
|
760
763
|
}
|
|
761
764
|
/**
|
|
@@ -764,10 +767,11 @@ var Transport = class {
|
|
|
764
767
|
* Destroys the transport. Any messages sent while the transport is destroyed will throw an error.
|
|
765
768
|
*/
|
|
766
769
|
destroy() {
|
|
770
|
+
this.state = "destroyed";
|
|
767
771
|
for (const session of this.sessions.values()) {
|
|
768
|
-
session.
|
|
772
|
+
session.close();
|
|
773
|
+
this.deleteSession(session);
|
|
769
774
|
}
|
|
770
|
-
this.state = "destroyed";
|
|
771
775
|
log?.info(`${this.clientId} -- manually destroyed transport`);
|
|
772
776
|
}
|
|
773
777
|
};
|
|
@@ -873,8 +877,7 @@ var ClientTransport = class extends Transport {
|
|
|
873
877
|
return bootHandler;
|
|
874
878
|
}
|
|
875
879
|
onDisconnect(conn, connectedTo) {
|
|
876
|
-
|
|
877
|
-
this.inflightConnectionPromises.delete(connectedTo);
|
|
880
|
+
this.inflightConnectionPromises.delete(connectedTo);
|
|
878
881
|
super.onDisconnect(conn, connectedTo);
|
|
879
882
|
}
|
|
880
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 {
|
|
@@ -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,16 +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
|
-
clearInterval(this.heartbeat);
|
|
337
|
-
}
|
|
338
338
|
inspectSendBuffer() {
|
|
339
339
|
return this.sendBuffer;
|
|
340
340
|
}
|
|
@@ -486,19 +486,18 @@ var Transport = class {
|
|
|
486
486
|
status: "connect",
|
|
487
487
|
conn
|
|
488
488
|
});
|
|
489
|
-
let
|
|
489
|
+
let oldSession = this.sessions.get(connectedTo);
|
|
490
490
|
const lastInstanceId = this.connectedInstanceIds.get(connectedTo);
|
|
491
|
-
if (
|
|
491
|
+
if (oldSession && lastInstanceId !== void 0 && lastInstanceId !== instanceId) {
|
|
492
492
|
log?.warn(
|
|
493
|
-
`${this.clientId} -- handshake from ${connectedTo}
|
|
493
|
+
`${this.clientId} -- handshake from ${connectedTo} is a different instance (got: ${instanceId}, last connected to: ${lastInstanceId}), starting a new session`
|
|
494
494
|
);
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
session = void 0;
|
|
495
|
+
oldSession.close();
|
|
496
|
+
this.deleteSession(oldSession);
|
|
497
|
+
oldSession = void 0;
|
|
499
498
|
}
|
|
500
499
|
this.connectedInstanceIds.set(connectedTo, instanceId);
|
|
501
|
-
if (
|
|
500
|
+
if (oldSession === void 0) {
|
|
502
501
|
const newSession = this.createSession(connectedTo, conn);
|
|
503
502
|
log?.info(
|
|
504
503
|
`${this.clientId} -- new connection (id: ${conn.debugId}) for new session (id: ${newSession.debugId}) to ${connectedTo}`
|
|
@@ -506,11 +505,11 @@ var Transport = class {
|
|
|
506
505
|
return newSession;
|
|
507
506
|
}
|
|
508
507
|
log?.info(
|
|
509
|
-
`${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}`
|
|
510
509
|
);
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
return
|
|
510
|
+
oldSession.replaceWithNewConnection(conn);
|
|
511
|
+
oldSession.sendBufferedMessages();
|
|
512
|
+
return oldSession;
|
|
514
513
|
}
|
|
515
514
|
createSession(connectedTo, conn) {
|
|
516
515
|
const session = new Session(
|
|
@@ -539,13 +538,14 @@ var Transport = class {
|
|
|
539
538
|
/**
|
|
540
539
|
* The downstream implementation needs to call this when a connection is closed.
|
|
541
540
|
* @param conn The connection object.
|
|
541
|
+
* @param connectedTo The peer we are connected to.
|
|
542
542
|
*/
|
|
543
543
|
onDisconnect(conn, connectedTo) {
|
|
544
544
|
this.eventDispatcher.dispatchEvent("connectionStatus", {
|
|
545
545
|
status: "disconnect",
|
|
546
546
|
conn
|
|
547
547
|
});
|
|
548
|
-
if (
|
|
548
|
+
if (this.state !== "open")
|
|
549
549
|
return;
|
|
550
550
|
const session = this.sessionByClientId(connectedTo);
|
|
551
551
|
log?.info(
|
|
@@ -588,6 +588,8 @@ var Transport = class {
|
|
|
588
588
|
* @param msg The received message.
|
|
589
589
|
*/
|
|
590
590
|
handleMsg(msg) {
|
|
591
|
+
if (this.state !== "open")
|
|
592
|
+
return;
|
|
591
593
|
const session = this.sessionByClientId(msg.from);
|
|
592
594
|
session.cancelGrace();
|
|
593
595
|
log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
|
|
@@ -664,10 +666,11 @@ var Transport = class {
|
|
|
664
666
|
* Closes the transport. Any messages sent while the transport is closed will be silently discarded.
|
|
665
667
|
*/
|
|
666
668
|
close() {
|
|
669
|
+
this.state = "closed";
|
|
667
670
|
for (const session of this.sessions.values()) {
|
|
668
|
-
session.
|
|
671
|
+
session.close();
|
|
672
|
+
this.deleteSession(session);
|
|
669
673
|
}
|
|
670
|
-
this.state = "closed";
|
|
671
674
|
log?.info(`${this.clientId} -- manually closed transport`);
|
|
672
675
|
}
|
|
673
676
|
/**
|
|
@@ -676,10 +679,11 @@ var Transport = class {
|
|
|
676
679
|
* Destroys the transport. Any messages sent while the transport is destroyed will throw an error.
|
|
677
680
|
*/
|
|
678
681
|
destroy() {
|
|
682
|
+
this.state = "destroyed";
|
|
679
683
|
for (const session of this.sessions.values()) {
|
|
680
|
-
session.
|
|
684
|
+
session.close();
|
|
685
|
+
this.deleteSession(session);
|
|
681
686
|
}
|
|
682
|
-
this.state = "destroyed";
|
|
683
687
|
log?.info(`${this.clientId} -- manually destroyed transport`);
|
|
684
688
|
}
|
|
685
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 {
|
|
@@ -288,17 +288,27 @@ var Session = class {
|
|
|
288
288
|
this.cancelGrace();
|
|
289
289
|
this.connection = newConn;
|
|
290
290
|
}
|
|
291
|
+
graceCb;
|
|
291
292
|
beginGrace(cb) {
|
|
293
|
+
this.graceCb = cb;
|
|
292
294
|
this.disconnectionGrace = setTimeout(() => {
|
|
293
|
-
this.
|
|
294
|
-
clearInterval(this.heartbeat);
|
|
295
|
+
this.close();
|
|
295
296
|
cb();
|
|
296
297
|
}, SESSION_DISCONNECT_GRACE_MS);
|
|
297
298
|
}
|
|
299
|
+
// called on reconnect of the underlying session
|
|
298
300
|
cancelGrace() {
|
|
299
301
|
this.heartbeatMisses = 0;
|
|
300
302
|
clearTimeout(this.disconnectionGrace);
|
|
301
303
|
}
|
|
304
|
+
// closed when we want to discard the whole session
|
|
305
|
+
// (i.e. shutdown or session disconnect)
|
|
306
|
+
close() {
|
|
307
|
+
this.closeStaleConnection(this.connection);
|
|
308
|
+
this.cancelGrace();
|
|
309
|
+
clearInterval(this.heartbeat);
|
|
310
|
+
this.resetBufferedMessages();
|
|
311
|
+
}
|
|
302
312
|
get connected() {
|
|
303
313
|
return this.connection !== void 0;
|
|
304
314
|
}
|
|
@@ -317,16 +327,6 @@ var Session = class {
|
|
|
317
327
|
this.seq++;
|
|
318
328
|
return msg;
|
|
319
329
|
}
|
|
320
|
-
/**
|
|
321
|
-
* Closes the out-going connection but doesn't remove the listeners
|
|
322
|
-
* for incoming messages. The connection will eventually call onClose
|
|
323
|
-
* when it is ready to be cleaned up and only then will {@link connection} be set back
|
|
324
|
-
* to undefined
|
|
325
|
-
*/
|
|
326
|
-
halfCloseConnection() {
|
|
327
|
-
this.connection?.close();
|
|
328
|
-
clearInterval(this.heartbeat);
|
|
329
|
-
}
|
|
330
330
|
inspectSendBuffer() {
|
|
331
331
|
return this.sendBuffer;
|
|
332
332
|
}
|
|
@@ -478,19 +478,18 @@ var Transport = class {
|
|
|
478
478
|
status: "connect",
|
|
479
479
|
conn
|
|
480
480
|
});
|
|
481
|
-
let
|
|
481
|
+
let oldSession = this.sessions.get(connectedTo);
|
|
482
482
|
const lastInstanceId = this.connectedInstanceIds.get(connectedTo);
|
|
483
|
-
if (
|
|
483
|
+
if (oldSession && lastInstanceId !== void 0 && lastInstanceId !== instanceId) {
|
|
484
484
|
log?.warn(
|
|
485
|
-
`${this.clientId} -- handshake from ${connectedTo}
|
|
485
|
+
`${this.clientId} -- handshake from ${connectedTo} is a different instance (got: ${instanceId}, last connected to: ${lastInstanceId}), starting a new session`
|
|
486
486
|
);
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
session = void 0;
|
|
487
|
+
oldSession.close();
|
|
488
|
+
this.deleteSession(oldSession);
|
|
489
|
+
oldSession = void 0;
|
|
491
490
|
}
|
|
492
491
|
this.connectedInstanceIds.set(connectedTo, instanceId);
|
|
493
|
-
if (
|
|
492
|
+
if (oldSession === void 0) {
|
|
494
493
|
const newSession = this.createSession(connectedTo, conn);
|
|
495
494
|
log?.info(
|
|
496
495
|
`${this.clientId} -- new connection (id: ${conn.debugId}) for new session (id: ${newSession.debugId}) to ${connectedTo}`
|
|
@@ -498,11 +497,11 @@ var Transport = class {
|
|
|
498
497
|
return newSession;
|
|
499
498
|
}
|
|
500
499
|
log?.info(
|
|
501
|
-
`${this.clientId} -- new connection (id: ${conn.debugId}) for existing session (id: ${
|
|
500
|
+
`${this.clientId} -- new connection (id: ${conn.debugId}) for existing session (id: ${oldSession.debugId}) to ${connectedTo}`
|
|
502
501
|
);
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
return
|
|
502
|
+
oldSession.replaceWithNewConnection(conn);
|
|
503
|
+
oldSession.sendBufferedMessages();
|
|
504
|
+
return oldSession;
|
|
506
505
|
}
|
|
507
506
|
createSession(connectedTo, conn) {
|
|
508
507
|
const session = new Session(
|
|
@@ -531,13 +530,14 @@ var Transport = class {
|
|
|
531
530
|
/**
|
|
532
531
|
* The downstream implementation needs to call this when a connection is closed.
|
|
533
532
|
* @param conn The connection object.
|
|
533
|
+
* @param connectedTo The peer we are connected to.
|
|
534
534
|
*/
|
|
535
535
|
onDisconnect(conn, connectedTo) {
|
|
536
536
|
this.eventDispatcher.dispatchEvent("connectionStatus", {
|
|
537
537
|
status: "disconnect",
|
|
538
538
|
conn
|
|
539
539
|
});
|
|
540
|
-
if (
|
|
540
|
+
if (this.state !== "open")
|
|
541
541
|
return;
|
|
542
542
|
const session = this.sessionByClientId(connectedTo);
|
|
543
543
|
log?.info(
|
|
@@ -580,6 +580,8 @@ var Transport = class {
|
|
|
580
580
|
* @param msg The received message.
|
|
581
581
|
*/
|
|
582
582
|
handleMsg(msg) {
|
|
583
|
+
if (this.state !== "open")
|
|
584
|
+
return;
|
|
583
585
|
const session = this.sessionByClientId(msg.from);
|
|
584
586
|
session.cancelGrace();
|
|
585
587
|
log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
|
|
@@ -656,10 +658,11 @@ var Transport = class {
|
|
|
656
658
|
* Closes the transport. Any messages sent while the transport is closed will be silently discarded.
|
|
657
659
|
*/
|
|
658
660
|
close() {
|
|
661
|
+
this.state = "closed";
|
|
659
662
|
for (const session of this.sessions.values()) {
|
|
660
|
-
session.
|
|
663
|
+
session.close();
|
|
664
|
+
this.deleteSession(session);
|
|
661
665
|
}
|
|
662
|
-
this.state = "closed";
|
|
663
666
|
log?.info(`${this.clientId} -- manually closed transport`);
|
|
664
667
|
}
|
|
665
668
|
/**
|
|
@@ -668,10 +671,11 @@ var Transport = class {
|
|
|
668
671
|
* Destroys the transport. Any messages sent while the transport is destroyed will throw an error.
|
|
669
672
|
*/
|
|
670
673
|
destroy() {
|
|
674
|
+
this.state = "destroyed";
|
|
671
675
|
for (const session of this.sessions.values()) {
|
|
672
|
-
session.
|
|
676
|
+
session.close();
|
|
677
|
+
this.deleteSession(session);
|
|
673
678
|
}
|
|
674
|
-
this.state = "destroyed";
|
|
675
679
|
log?.info(`${this.clientId} -- manually destroyed transport`);
|
|
676
680
|
}
|
|
677
681
|
};
|
|
@@ -777,8 +781,7 @@ var ClientTransport = class extends Transport {
|
|
|
777
781
|
return bootHandler;
|
|
778
782
|
}
|
|
779
783
|
onDisconnect(conn, connectedTo) {
|
|
780
|
-
|
|
781
|
-
this.inflightConnectionPromises.delete(connectedTo);
|
|
784
|
+
this.inflightConnectionPromises.delete(connectedTo);
|
|
782
785
|
super.onDisconnect(conn, connectedTo);
|
|
783
786
|
}
|
|
784
787
|
};
|
|
@@ -864,9 +867,10 @@ var WebSocketClientTransport = class extends ClientTransport {
|
|
|
864
867
|
resolve({ err: evt.reason });
|
|
865
868
|
};
|
|
866
869
|
const onError = (evt) => {
|
|
870
|
+
const err = evt.error;
|
|
867
871
|
ws.removeEventListener("error", onError);
|
|
868
872
|
ws.removeEventListener("close", onClose);
|
|
869
|
-
resolve({ err:
|
|
873
|
+
resolve({ err: err.message || err.code || "unknown error" });
|
|
870
874
|
};
|
|
871
875
|
ws.addEventListener("open", onOpen);
|
|
872
876
|
ws.addEventListener("close", onClose);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import WebSocket from 'isomorphic-ws';
|
|
2
|
-
import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-
|
|
3
|
-
import { W as WebSocketConnection } from '../../../connection-
|
|
2
|
+
import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-1afc5580.js';
|
|
3
|
+
import { W as WebSocketConnection } from '../../../connection-4a839b9a.js';
|
|
4
4
|
import '../../../types-3e5768ec.js';
|
|
5
5
|
import '@sinclair/typebox';
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import WebSocket from 'isomorphic-ws';
|
|
2
|
-
import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-
|
|
3
|
-
import { W as WebSocketConnection } from '../../../connection-
|
|
2
|
+
import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-1afc5580.js';
|
|
3
|
+
import { W as WebSocketConnection } from '../../../connection-4a839b9a.js';
|
|
4
4
|
import '../../../types-3e5768ec.js';
|
|
5
5
|
import '@sinclair/typebox';
|
|
6
6
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
WebSocketConnection
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-6OAKPO5R.js";
|
|
4
4
|
import {
|
|
5
5
|
ClientTransport
|
|
6
|
-
} from "../../../chunk-
|
|
6
|
+
} from "../../../chunk-2PKONGC3.js";
|
|
7
7
|
import "../../../chunk-GZ7HCLLM.js";
|
|
8
8
|
import "../../../chunk-XFFS4UOD.js";
|
|
9
9
|
import {
|
|
@@ -58,9 +58,10 @@ var WebSocketClientTransport = class extends ClientTransport {
|
|
|
58
58
|
resolve({ err: evt.reason });
|
|
59
59
|
};
|
|
60
60
|
const onError = (evt) => {
|
|
61
|
+
const err = evt.error;
|
|
61
62
|
ws.removeEventListener("error", onError);
|
|
62
63
|
ws.removeEventListener("close", onClose);
|
|
63
|
-
resolve({ err:
|
|
64
|
+
resolve({ err: err.message || err.code || "unknown error" });
|
|
64
65
|
};
|
|
65
66
|
ws.addEventListener("open", onOpen);
|
|
66
67
|
ws.addEventListener("close", onClose);
|