@replit/river 0.17.3 → 0.18.0
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 +4 -3
- package/dist/{chunk-7WY3Z5ZN.js → chunk-CLY7AQ25.js} +169 -95
- package/dist/{chunk-4C2OXQJB.js → chunk-TIFNW5GQ.js} +62 -65
- package/dist/{chunk-F3LFO3GU.js → chunk-UEKU6XRG.js} +1 -1
- package/dist/chunk-YITXOAPA.js +72 -0
- package/dist/{chunk-Q7OSVPZ5.js → chunk-ZPPKYJI7.js} +1 -1
- package/dist/{connection-713c8c66.d.ts → connection-32bf6608.d.ts} +1 -1
- package/dist/{connection-b79329de.d.ts → connection-df5f32ee.d.ts} +1 -1
- package/dist/{index-80f87385.d.ts → index-314e676a.d.ts} +4 -86
- package/dist/index-6118cd48.d.ts +117 -0
- package/dist/logging/index.cjs +63 -27
- package/dist/logging/index.d.cts +2 -34
- package/dist/logging/index.d.ts +2 -34
- package/dist/logging/index.js +7 -7
- package/dist/{procedures-79a5f07e.d.ts → procedures-74a10937.d.ts} +4 -3
- package/dist/router/index.cjs +63 -66
- package/dist/router/index.d.cts +43 -42
- package/dist/router/index.d.ts +43 -42
- package/dist/router/index.js +2 -2
- package/dist/transport/impls/uds/client.cjs +152 -84
- package/dist/transport/impls/uds/client.d.cts +3 -2
- package/dist/transport/impls/uds/client.d.ts +3 -2
- package/dist/transport/impls/uds/client.js +7 -4
- package/dist/transport/impls/uds/server.cjs +116 -65
- package/dist/transport/impls/uds/server.d.cts +3 -2
- package/dist/transport/impls/uds/server.d.ts +3 -2
- package/dist/transport/impls/uds/server.js +3 -3
- package/dist/transport/impls/ws/client.cjs +156 -87
- package/dist/transport/impls/ws/client.d.cts +3 -2
- package/dist/transport/impls/ws/client.d.ts +3 -2
- package/dist/transport/impls/ws/client.js +11 -7
- package/dist/transport/impls/ws/server.cjs +116 -65
- package/dist/transport/impls/ws/server.d.cts +4 -3
- package/dist/transport/impls/ws/server.d.ts +4 -3
- package/dist/transport/impls/ws/server.js +3 -3
- package/dist/transport/index.cjs +170 -96
- package/dist/transport/index.d.cts +2 -1
- package/dist/transport/index.d.ts +2 -1
- package/dist/transport/index.js +2 -2
- package/dist/util/testHelpers.cjs +65 -32
- package/dist/util/testHelpers.d.cts +8 -7
- package/dist/util/testHelpers.d.ts +8 -7
- package/dist/util/testHelpers.js +20 -18
- package/package.json +1 -1
- package/dist/chunk-H4BYJELI.js +0 -37
package/README.md
CHANGED
|
@@ -168,12 +168,13 @@ if (result.ok) {
|
|
|
168
168
|
To add logging,
|
|
169
169
|
|
|
170
170
|
```ts
|
|
171
|
-
import { bindLogger,
|
|
171
|
+
import { bindLogger, stringLogger } from '@replit/river/logging';
|
|
172
172
|
|
|
173
|
-
bindLogger(
|
|
174
|
-
setLevel('info');
|
|
173
|
+
bindLogger(stringLogger, 'info');
|
|
175
174
|
```
|
|
176
175
|
|
|
176
|
+
You can define your own logging functions that satisfy the `LogFn` type.
|
|
177
|
+
|
|
177
178
|
### Connection status
|
|
178
179
|
|
|
179
180
|
River defines two types of reconnects:
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from "./chunk-VH3NGOXQ.js";
|
|
11
11
|
import {
|
|
12
12
|
log
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-YITXOAPA.js";
|
|
14
14
|
import {
|
|
15
15
|
NaiveJsonCodec
|
|
16
16
|
} from "./chunk-GZ7HCLLM.js";
|
|
@@ -115,6 +115,14 @@ var Session = class {
|
|
|
115
115
|
options.heartbeatIntervalMs
|
|
116
116
|
);
|
|
117
117
|
}
|
|
118
|
+
get loggingMetadata() {
|
|
119
|
+
return {
|
|
120
|
+
clientId: this.from,
|
|
121
|
+
connectedTo: this.to,
|
|
122
|
+
sessionId: this.id,
|
|
123
|
+
connId: this.connection?.debugId
|
|
124
|
+
};
|
|
125
|
+
}
|
|
118
126
|
/**
|
|
119
127
|
* Sends a message over the session's connection.
|
|
120
128
|
* If the connection is not ready or the message fails to send, the message can be buffered for retry unless skipped.
|
|
@@ -125,26 +133,37 @@ var Session = class {
|
|
|
125
133
|
*/
|
|
126
134
|
send(msg) {
|
|
127
135
|
const fullMsg = this.constructMsg(msg);
|
|
128
|
-
log?.debug(
|
|
136
|
+
log?.debug(`sending msg`, {
|
|
137
|
+
...this.loggingMetadata,
|
|
138
|
+
fullTransportMessage: fullMsg
|
|
139
|
+
});
|
|
129
140
|
if (this.connection) {
|
|
130
141
|
const ok = this.connection.send(this.codec.toBuffer(fullMsg));
|
|
131
142
|
if (ok)
|
|
132
143
|
return fullMsg.id;
|
|
133
144
|
log?.info(
|
|
134
|
-
|
|
145
|
+
`failed to send msg to ${fullMsg.to}, connection is probably dead`,
|
|
146
|
+
{
|
|
147
|
+
...this.loggingMetadata,
|
|
148
|
+
fullTransportMessage: fullMsg
|
|
149
|
+
}
|
|
135
150
|
);
|
|
136
151
|
} else {
|
|
137
152
|
log?.info(
|
|
138
|
-
|
|
153
|
+
`failed to send msg to ${fullMsg.to}, connection not ready yet`,
|
|
154
|
+
{ ...this.loggingMetadata, fullTransportMessage: fullMsg }
|
|
139
155
|
);
|
|
140
156
|
}
|
|
141
157
|
return fullMsg.id;
|
|
142
158
|
}
|
|
143
159
|
sendHeartbeat() {
|
|
144
|
-
|
|
160
|
+
const misses = this.heartbeatMisses;
|
|
161
|
+
const missDuration = misses * this.options.heartbeatIntervalMs;
|
|
162
|
+
if (misses > this.options.heartbeatsUntilDead) {
|
|
145
163
|
if (this.connection) {
|
|
146
164
|
log?.info(
|
|
147
|
-
|
|
165
|
+
`closing connection to ${this.to} due to inactivity (missed ${misses} heartbeats which is ${missDuration}ms)`,
|
|
166
|
+
this.loggingMetadata
|
|
148
167
|
);
|
|
149
168
|
this.closeStaleConnection();
|
|
150
169
|
}
|
|
@@ -166,26 +185,36 @@ var Session = class {
|
|
|
166
185
|
}
|
|
167
186
|
sendBufferedMessages() {
|
|
168
187
|
if (!this.connection) {
|
|
169
|
-
const msg =
|
|
170
|
-
log?.error(msg);
|
|
188
|
+
const msg = `tried sending buffered messages without a connection (if you hit this code path something is seriously wrong)`;
|
|
189
|
+
log?.error(msg, this.loggingMetadata);
|
|
171
190
|
throw new Error(msg);
|
|
172
191
|
}
|
|
173
192
|
log?.info(
|
|
174
|
-
|
|
193
|
+
`resending ${this.sendBuffer.length} buffered messages`,
|
|
194
|
+
this.loggingMetadata
|
|
175
195
|
);
|
|
176
196
|
for (const msg of this.sendBuffer) {
|
|
177
|
-
log?.debug(
|
|
197
|
+
log?.debug(`resending msg`, {
|
|
198
|
+
...this.loggingMetadata,
|
|
199
|
+
fullTransportMessage: msg
|
|
200
|
+
});
|
|
178
201
|
const ok = this.connection.send(this.codec.toBuffer(msg));
|
|
179
202
|
if (!ok) {
|
|
180
|
-
const
|
|
181
|
-
log?.error(
|
|
182
|
-
|
|
203
|
+
const errMsg = `failed to send buffered message to ${this.to} (if you hit this code path something is seriously wrong)`;
|
|
204
|
+
log?.error(errMsg, {
|
|
205
|
+
...this.loggingMetadata,
|
|
206
|
+
fullTransportMessage: msg
|
|
207
|
+
});
|
|
208
|
+
throw new Error(errMsg);
|
|
183
209
|
}
|
|
184
210
|
}
|
|
185
211
|
}
|
|
186
212
|
updateBookkeeping(ack, seq) {
|
|
187
213
|
if (seq + 1 < this.ack) {
|
|
188
|
-
log?.error(
|
|
214
|
+
log?.error(
|
|
215
|
+
`received stale seq ${seq} + 1 < ${this.ack}`,
|
|
216
|
+
this.loggingMetadata
|
|
217
|
+
);
|
|
189
218
|
return;
|
|
190
219
|
}
|
|
191
220
|
this.sendBuffer = this.sendBuffer.filter((unacked) => unacked.seq >= ack);
|
|
@@ -195,7 +224,8 @@ var Session = class {
|
|
|
195
224
|
if (this.connection === void 0 || this.connection === conn)
|
|
196
225
|
return;
|
|
197
226
|
log?.info(
|
|
198
|
-
|
|
227
|
+
`closing old inner connection from session to ${this.to}`,
|
|
228
|
+
this.loggingMetadata
|
|
199
229
|
);
|
|
200
230
|
this.connection.close();
|
|
201
231
|
this.connection = void 0;
|
|
@@ -207,7 +237,8 @@ var Session = class {
|
|
|
207
237
|
}
|
|
208
238
|
beginGrace(cb) {
|
|
209
239
|
log?.info(
|
|
210
|
-
|
|
240
|
+
`starting ${this.options.sessionDisconnectGraceMs}ms grace period until session to ${this.to} is closed`,
|
|
241
|
+
this.loggingMetadata
|
|
211
242
|
);
|
|
212
243
|
this.disconnectionGrace = setTimeout(() => {
|
|
213
244
|
this.close();
|
|
@@ -405,7 +436,8 @@ var Transport = class {
|
|
|
405
436
|
let oldSession = this.sessions.get(connectedTo);
|
|
406
437
|
if (oldSession?.advertisedSessionId && oldSession.advertisedSessionId !== advertisedSessionId) {
|
|
407
438
|
log?.warn(
|
|
408
|
-
|
|
439
|
+
`connection from ${connectedTo} is a different session (id: ${advertisedSessionId}, last connected to: ${oldSession.advertisedSessionId}), killing old session and starting a new one`,
|
|
440
|
+
oldSession.loggingMetadata
|
|
409
441
|
);
|
|
410
442
|
this.deleteSession(oldSession);
|
|
411
443
|
oldSession = void 0;
|
|
@@ -414,16 +446,18 @@ var Transport = class {
|
|
|
414
446
|
const newSession = this.createSession(connectedTo, conn);
|
|
415
447
|
newSession.advertisedSessionId = advertisedSessionId;
|
|
416
448
|
log?.info(
|
|
417
|
-
|
|
449
|
+
`new connection for new session to ${connectedTo}`,
|
|
450
|
+
newSession.loggingMetadata
|
|
418
451
|
);
|
|
419
452
|
return newSession;
|
|
420
453
|
}
|
|
421
|
-
log?.info(
|
|
422
|
-
`${this.clientId} -- new connection (id: ${conn.debugId}) for existing session (id: ${oldSession.id}) to ${connectedTo}`
|
|
423
|
-
);
|
|
424
454
|
oldSession.replaceWithNewConnection(conn);
|
|
425
455
|
oldSession.sendBufferedMessages();
|
|
426
456
|
oldSession.advertisedSessionId = advertisedSessionId;
|
|
457
|
+
log?.info(
|
|
458
|
+
`new connection for existing session to ${connectedTo}`,
|
|
459
|
+
oldSession.loggingMetadata
|
|
460
|
+
);
|
|
427
461
|
return oldSession;
|
|
428
462
|
}
|
|
429
463
|
createSession(to, conn) {
|
|
@@ -445,7 +479,8 @@ var Transport = class {
|
|
|
445
479
|
if (!session) {
|
|
446
480
|
session = this.createSession(to, conn);
|
|
447
481
|
log?.info(
|
|
448
|
-
|
|
482
|
+
`no session for ${to}, created a new one`,
|
|
483
|
+
session.loggingMetadata
|
|
449
484
|
);
|
|
450
485
|
}
|
|
451
486
|
return session;
|
|
@@ -454,7 +489,8 @@ var Transport = class {
|
|
|
454
489
|
session.close();
|
|
455
490
|
this.sessions.delete(session.to);
|
|
456
491
|
log?.info(
|
|
457
|
-
|
|
492
|
+
`session ${session.id} disconnect from ${session.to}`,
|
|
493
|
+
session.loggingMetadata
|
|
458
494
|
);
|
|
459
495
|
this.eventDispatcher.dispatchEvent("sessionStatus", {
|
|
460
496
|
status: "disconnect",
|
|
@@ -483,17 +519,15 @@ var Transport = class {
|
|
|
483
519
|
const parsedMsg = this.codec.fromBuffer(msg);
|
|
484
520
|
if (parsedMsg === null) {
|
|
485
521
|
const decodedBuffer = new TextDecoder().decode(Buffer.from(msg));
|
|
486
|
-
log?.error(
|
|
487
|
-
|
|
488
|
-
);
|
|
522
|
+
log?.error(`received malformed msg, killing conn: ${decodedBuffer}`, {
|
|
523
|
+
clientId: this.clientId
|
|
524
|
+
});
|
|
489
525
|
return null;
|
|
490
526
|
}
|
|
491
527
|
if (!Value.Check(OpaqueTransportMessageSchema, parsedMsg)) {
|
|
492
|
-
log?.error(
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
)}`
|
|
496
|
-
);
|
|
528
|
+
log?.error(`received invalid msg: ${JSON.stringify(parsedMsg)}`, {
|
|
529
|
+
clientId: this.clientId
|
|
530
|
+
});
|
|
497
531
|
return null;
|
|
498
532
|
}
|
|
499
533
|
return parsedMsg;
|
|
@@ -508,26 +542,29 @@ var Transport = class {
|
|
|
508
542
|
return;
|
|
509
543
|
const session = this.sessions.get(msg.from);
|
|
510
544
|
if (!session) {
|
|
511
|
-
|
|
512
|
-
|
|
545
|
+
log?.error(`(invariant violation) no existing session for ${msg.from}`, {
|
|
546
|
+
clientId: this.clientId,
|
|
547
|
+
fullTransportMessage: msg
|
|
548
|
+
});
|
|
513
549
|
return;
|
|
514
550
|
}
|
|
515
551
|
session.cancelGrace();
|
|
516
|
-
log?.debug(
|
|
552
|
+
log?.debug(`received msg`, {
|
|
553
|
+
clientId: this.clientId,
|
|
554
|
+
fullTransportMessage: msg
|
|
555
|
+
});
|
|
517
556
|
if (msg.seq !== session.nextExpectedSeq) {
|
|
518
557
|
if (msg.seq < session.nextExpectedSeq) {
|
|
519
558
|
log?.debug(
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
)}`
|
|
559
|
+
`received duplicate msg (got seq: ${msg.seq}, wanted seq: ${session.nextExpectedSeq}), discarding`,
|
|
560
|
+
{ clientId: this.clientId, fullTransportMessage: msg }
|
|
523
561
|
);
|
|
524
562
|
} else {
|
|
525
563
|
const errMsg = `received out-of-order msg (got seq: ${msg.seq}, wanted seq: ${session.nextExpectedSeq})`;
|
|
526
|
-
log?.error(
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
);
|
|
564
|
+
log?.error(`${errMsg}, marking connection as dead`, {
|
|
565
|
+
clientId: this.clientId,
|
|
566
|
+
fullTransportMessage: msg
|
|
567
|
+
});
|
|
531
568
|
this.protocolError(ProtocolError.MessageOrderingViolated, errMsg);
|
|
532
569
|
session.close();
|
|
533
570
|
}
|
|
@@ -537,7 +574,10 @@ var Transport = class {
|
|
|
537
574
|
if (!isAck(msg.controlFlags)) {
|
|
538
575
|
this.eventDispatcher.dispatchEvent("message", msg);
|
|
539
576
|
} else {
|
|
540
|
-
log?.debug(
|
|
577
|
+
log?.debug(`discarding msg (ack bit set)`, {
|
|
578
|
+
clientId: this.clientId,
|
|
579
|
+
fullTransportMessage: msg
|
|
580
|
+
});
|
|
541
581
|
}
|
|
542
582
|
}
|
|
543
583
|
/**
|
|
@@ -565,15 +605,17 @@ var Transport = class {
|
|
|
565
605
|
send(to, msg) {
|
|
566
606
|
if (this.state === "destroyed") {
|
|
567
607
|
const err = "transport is destroyed, cant send";
|
|
568
|
-
log?.error(
|
|
608
|
+
log?.error(err, {
|
|
609
|
+
clientId: this.clientId,
|
|
610
|
+
partialTransportMessage: msg
|
|
611
|
+
});
|
|
569
612
|
this.protocolError(ProtocolError.UseAfterDestroy, err);
|
|
570
613
|
return void 0;
|
|
571
614
|
} else if (this.state === "closed") {
|
|
572
|
-
log?.info(
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
);
|
|
615
|
+
log?.info(`transport closed when sending, discarding`, {
|
|
616
|
+
clientId: this.clientId,
|
|
617
|
+
partialTransportMessage: msg
|
|
618
|
+
});
|
|
577
619
|
return void 0;
|
|
578
620
|
}
|
|
579
621
|
return this.getOrCreateSession(to).send(msg);
|
|
@@ -601,7 +643,7 @@ var Transport = class {
|
|
|
601
643
|
for (const session of this.sessions.values()) {
|
|
602
644
|
this.deleteSession(session);
|
|
603
645
|
}
|
|
604
|
-
log?.info(
|
|
646
|
+
log?.info(`manually closed transport`, { clientId: this.clientId });
|
|
605
647
|
}
|
|
606
648
|
/**
|
|
607
649
|
* Default destroy implementation for transports. You should override this in the downstream
|
|
@@ -613,7 +655,7 @@ var Transport = class {
|
|
|
613
655
|
for (const session of this.sessions.values()) {
|
|
614
656
|
this.deleteSession(session);
|
|
615
657
|
}
|
|
616
|
-
log?.info(
|
|
658
|
+
log?.info(`manually destroyed transport`, { clientId: this.clientId });
|
|
617
659
|
}
|
|
618
660
|
};
|
|
619
661
|
var ClientTransport = class extends Transport {
|
|
@@ -669,18 +711,22 @@ var ClientTransport = class extends Transport {
|
|
|
669
711
|
if (session) {
|
|
670
712
|
this.onDisconnect(conn, session);
|
|
671
713
|
}
|
|
672
|
-
log?.info(
|
|
673
|
-
|
|
674
|
-
|
|
714
|
+
log?.info(`connection to ${to} disconnected`, {
|
|
715
|
+
...session?.loggingMetadata,
|
|
716
|
+
clientId: this.clientId,
|
|
717
|
+
connectedTo: to
|
|
718
|
+
});
|
|
675
719
|
this.inflightConnectionPromises.delete(to);
|
|
676
720
|
if (this.reconnectOnConnectionDrop) {
|
|
677
721
|
void this.connect(to);
|
|
678
722
|
}
|
|
679
723
|
});
|
|
680
724
|
conn.addErrorListener((err) => {
|
|
681
|
-
log?.warn(
|
|
682
|
-
|
|
683
|
-
|
|
725
|
+
log?.warn(`error in connection to ${to}: ${coerceErrorString(err)}`, {
|
|
726
|
+
...session?.loggingMetadata,
|
|
727
|
+
clientId: this.clientId,
|
|
728
|
+
connectedTo: to
|
|
729
|
+
});
|
|
684
730
|
});
|
|
685
731
|
}
|
|
686
732
|
receiveHandshakeResponseMessage(data, conn) {
|
|
@@ -693,11 +739,11 @@ var ClientTransport = class extends Transport {
|
|
|
693
739
|
return false;
|
|
694
740
|
}
|
|
695
741
|
if (!Value.Check(ControlMessageHandshakeResponseSchema, parsed.payload)) {
|
|
696
|
-
log?.warn(
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
);
|
|
742
|
+
log?.warn(`received invalid handshake resp`, {
|
|
743
|
+
clientId: this.clientId,
|
|
744
|
+
connectedTo: parsed.from,
|
|
745
|
+
fullTransportMessage: parsed
|
|
746
|
+
});
|
|
701
747
|
this.protocolError(
|
|
702
748
|
ProtocolError.HandshakeFailed,
|
|
703
749
|
"invalid handshake resp"
|
|
@@ -705,18 +751,22 @@ var ClientTransport = class extends Transport {
|
|
|
705
751
|
return false;
|
|
706
752
|
}
|
|
707
753
|
if (!parsed.payload.status.ok) {
|
|
708
|
-
log?.warn(
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
);
|
|
754
|
+
log?.warn(`received invalid handshake resp`, {
|
|
755
|
+
clientId: this.clientId,
|
|
756
|
+
connectedTo: parsed.from,
|
|
757
|
+
fullTransportMessage: parsed
|
|
758
|
+
});
|
|
713
759
|
this.protocolError(
|
|
714
760
|
ProtocolError.HandshakeFailed,
|
|
715
761
|
parsed.payload.status.reason
|
|
716
762
|
);
|
|
717
763
|
return false;
|
|
718
764
|
}
|
|
719
|
-
log?.debug(
|
|
765
|
+
log?.debug(`handshake from ${parsed.from} ok`, {
|
|
766
|
+
clientId: this.clientId,
|
|
767
|
+
connectedTo: parsed.from,
|
|
768
|
+
fullTransportMessage: parsed
|
|
769
|
+
});
|
|
720
770
|
const session = this.onConnect(
|
|
721
771
|
conn,
|
|
722
772
|
parsed.from,
|
|
@@ -733,7 +783,8 @@ var ClientTransport = class extends Transport {
|
|
|
733
783
|
const canProceedWithConnection = () => this.state === "open";
|
|
734
784
|
if (!canProceedWithConnection()) {
|
|
735
785
|
log?.info(
|
|
736
|
-
|
|
786
|
+
`transport state is no longer open, cancelling attempt to connect to ${to}`,
|
|
787
|
+
{ clientId: this.clientId, connectedTo: to }
|
|
737
788
|
);
|
|
738
789
|
return;
|
|
739
790
|
}
|
|
@@ -742,7 +793,7 @@ var ClientTransport = class extends Transport {
|
|
|
742
793
|
const budgetConsumed = this.retryBudget.getBudgetConsumed(to);
|
|
743
794
|
if (!this.retryBudget.hasBudget(to)) {
|
|
744
795
|
const errMsg = `tried to connect to ${to} but retry budget exceeded (more than ${budgetConsumed} attempts in the last ${this.retryBudget.totalBudgetRestoreTime}ms)`;
|
|
745
|
-
log?.warn(
|
|
796
|
+
log?.warn(errMsg, { clientId: this.clientId, connectedTo: to });
|
|
746
797
|
this.protocolError(ProtocolError.RetriesExceeded, errMsg);
|
|
747
798
|
return;
|
|
748
799
|
}
|
|
@@ -751,9 +802,10 @@ var ClientTransport = class extends Transport {
|
|
|
751
802
|
if (backoffMs > 0) {
|
|
752
803
|
sleep = new Promise((resolve) => setTimeout(resolve, backoffMs));
|
|
753
804
|
}
|
|
754
|
-
log?.info(
|
|
755
|
-
|
|
756
|
-
|
|
805
|
+
log?.info(`attempting connection to ${to} (${backoffMs}ms backoff)`, {
|
|
806
|
+
clientId: this.clientId,
|
|
807
|
+
connectedTo: to
|
|
808
|
+
});
|
|
757
809
|
this.retryBudget.consumeBudget(to);
|
|
758
810
|
reconnectPromise = sleep.then(() => {
|
|
759
811
|
if (!canProceedWithConnection()) {
|
|
@@ -762,7 +814,12 @@ var ClientTransport = class extends Transport {
|
|
|
762
814
|
}).then(() => this.createNewOutgoingConnection(to)).then((conn) => {
|
|
763
815
|
if (!canProceedWithConnection()) {
|
|
764
816
|
log?.info(
|
|
765
|
-
|
|
817
|
+
`transport state is no longer open, closing pre-handshake connection to ${to}`,
|
|
818
|
+
{
|
|
819
|
+
clientId: this.clientId,
|
|
820
|
+
connectedTo: to,
|
|
821
|
+
connId: conn.debugId
|
|
822
|
+
}
|
|
766
823
|
);
|
|
767
824
|
conn.close();
|
|
768
825
|
throw new Error("transport state is no longer open");
|
|
@@ -772,9 +829,10 @@ var ClientTransport = class extends Transport {
|
|
|
772
829
|
});
|
|
773
830
|
this.inflightConnectionPromises.set(to, reconnectPromise);
|
|
774
831
|
} else {
|
|
775
|
-
log?.info(
|
|
776
|
-
|
|
777
|
-
|
|
832
|
+
log?.info(`attempting connection to ${to} (reusing previous attempt)`, {
|
|
833
|
+
clientId: this.clientId,
|
|
834
|
+
connectedTo: to
|
|
835
|
+
});
|
|
778
836
|
}
|
|
779
837
|
try {
|
|
780
838
|
await reconnectPromise;
|
|
@@ -782,11 +840,15 @@ var ClientTransport = class extends Transport {
|
|
|
782
840
|
this.inflightConnectionPromises.delete(to);
|
|
783
841
|
const errStr = coerceErrorString(error);
|
|
784
842
|
if (!this.reconnectOnConnectionDrop || !canProceedWithConnection()) {
|
|
785
|
-
log?.warn(
|
|
843
|
+
log?.warn(`connection to ${to} failed (${errStr})`, {
|
|
844
|
+
clientId: this.clientId,
|
|
845
|
+
connectedTo: to
|
|
846
|
+
});
|
|
786
847
|
} else {
|
|
787
|
-
log?.warn(
|
|
788
|
-
|
|
789
|
-
|
|
848
|
+
log?.warn(`connection to ${to} failed (${errStr}), retrying`, {
|
|
849
|
+
clientId: this.clientId,
|
|
850
|
+
connectedTo: to
|
|
851
|
+
});
|
|
790
852
|
return this.connect(to);
|
|
791
853
|
}
|
|
792
854
|
}
|
|
@@ -798,7 +860,10 @@ var ClientTransport = class extends Transport {
|
|
|
798
860
|
sendHandshake(to, conn) {
|
|
799
861
|
const session = this.getOrCreateSession(to, conn);
|
|
800
862
|
const requestMsg = handshakeRequestMessage(this.clientId, to, session.id);
|
|
801
|
-
log?.debug(
|
|
863
|
+
log?.debug(`sending handshake request to ${to}`, {
|
|
864
|
+
clientId: this.clientId,
|
|
865
|
+
connectedTo: to
|
|
866
|
+
});
|
|
802
867
|
conn.send(this.codec.toBuffer(requestMsg));
|
|
803
868
|
}
|
|
804
869
|
close() {
|
|
@@ -809,16 +874,18 @@ var ClientTransport = class extends Transport {
|
|
|
809
874
|
var ServerTransport = class extends Transport {
|
|
810
875
|
constructor(clientId, providedOptions) {
|
|
811
876
|
super(clientId, providedOptions);
|
|
812
|
-
log?.info(
|
|
813
|
-
|
|
814
|
-
|
|
877
|
+
log?.info(`initiated server transport`, {
|
|
878
|
+
clientId: this.clientId,
|
|
879
|
+
protocolVersion: PROTOCOL_VERSION
|
|
880
|
+
});
|
|
815
881
|
}
|
|
816
882
|
handleConnection(conn) {
|
|
817
883
|
if (this.state !== "open")
|
|
818
884
|
return;
|
|
819
|
-
log?.info(
|
|
820
|
-
|
|
821
|
-
|
|
885
|
+
log?.info(`new incoming connection`, {
|
|
886
|
+
clientId: this.clientId,
|
|
887
|
+
connId: conn.debugId
|
|
888
|
+
});
|
|
822
889
|
let session = void 0;
|
|
823
890
|
const client = () => session?.to ?? "unknown";
|
|
824
891
|
const handshakeHandler = (data) => {
|
|
@@ -843,16 +910,18 @@ var ServerTransport = class extends Transport {
|
|
|
843
910
|
conn.addCloseListener(() => {
|
|
844
911
|
if (!session)
|
|
845
912
|
return;
|
|
846
|
-
log?.info(
|
|
847
|
-
|
|
848
|
-
|
|
913
|
+
log?.info(`connection to ${client()} disconnected`, {
|
|
914
|
+
clientId: this.clientId,
|
|
915
|
+
connId: conn.debugId
|
|
916
|
+
});
|
|
849
917
|
this.onDisconnect(conn, session);
|
|
850
918
|
});
|
|
851
919
|
conn.addErrorListener((err) => {
|
|
852
920
|
if (!session)
|
|
853
921
|
return;
|
|
854
922
|
log?.warn(
|
|
855
|
-
|
|
923
|
+
`connection to ${client()} got an error: ${coerceErrorString(err)}`,
|
|
924
|
+
{ clientId: this.clientId, connId: conn.debugId }
|
|
856
925
|
);
|
|
857
926
|
});
|
|
858
927
|
}
|
|
@@ -872,7 +941,10 @@ var ServerTransport = class extends Transport {
|
|
|
872
941
|
reason
|
|
873
942
|
});
|
|
874
943
|
conn.send(this.codec.toBuffer(responseMsg2));
|
|
875
|
-
log?.warn(`${
|
|
944
|
+
log?.warn(`${reason}: ${JSON.stringify(parsed)}`, {
|
|
945
|
+
clientId: this.clientId,
|
|
946
|
+
connId: conn.debugId
|
|
947
|
+
});
|
|
876
948
|
this.protocolError(
|
|
877
949
|
ProtocolError.HandshakeFailed,
|
|
878
950
|
"invalid handshake request"
|
|
@@ -888,14 +960,16 @@ var ServerTransport = class extends Transport {
|
|
|
888
960
|
});
|
|
889
961
|
conn.send(this.codec.toBuffer(responseMsg2));
|
|
890
962
|
log?.warn(
|
|
891
|
-
|
|
963
|
+
`received handshake msg with incompatible protocol version (got: ${gotVersion}, expected: ${PROTOCOL_VERSION})`,
|
|
964
|
+
{ clientId: this.clientId, connId: conn.debugId }
|
|
892
965
|
);
|
|
893
966
|
this.protocolError(ProtocolError.HandshakeFailed, reason);
|
|
894
967
|
return false;
|
|
895
968
|
}
|
|
896
969
|
const session = this.getOrCreateSession(parsed.from, conn);
|
|
897
970
|
log?.debug(
|
|
898
|
-
|
|
971
|
+
`handshake from ${parsed.from} ok, responding with handshake success`,
|
|
972
|
+
{ clientId: this.clientId, connId: conn.debugId }
|
|
899
973
|
);
|
|
900
974
|
const responseMsg = handshakeResponseMessage(this.clientId, parsed.from, {
|
|
901
975
|
ok: true,
|