@replit/river 0.23.6 → 0.23.7
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 +10 -3
- package/dist/{chunk-ZFN6I2GJ.js → chunk-2KC75LS4.js} +2 -2
- package/dist/{chunk-GX2YS7BY.js → chunk-6LCL2ZZF.js} +17 -31
- package/dist/chunk-6LCL2ZZF.js.map +1 -0
- package/dist/{chunk-7E53HHNS.js → chunk-M3TGXFWT.js} +33 -31
- package/dist/chunk-M3TGXFWT.js.map +1 -0
- package/dist/{chunk-2PSMEETT.js → chunk-MFF6IPBA.js} +24 -11
- package/dist/{chunk-2PSMEETT.js.map → chunk-MFF6IPBA.js.map} +1 -1
- package/dist/{chunk-NJJYBNYM.js → chunk-RLVU5DRX.js} +2 -2
- package/dist/{chunk-NB3OHLXB.js → chunk-XYFXRL7Q.js} +165 -101
- package/dist/chunk-XYFXRL7Q.js.map +1 -0
- package/dist/{connection-e257f6b7.d.ts → connection-6ce35bd5.d.ts} +1 -1
- package/dist/{connection-5331d77f.d.ts → connection-a3fdfa3a.d.ts} +1 -1
- package/dist/{index-926aea33.d.ts → index-60f03cb7.d.ts} +5 -2
- package/dist/logging/index.cjs +6 -73
- package/dist/logging/index.cjs.map +1 -1
- package/dist/logging/index.d.cts +1 -1
- package/dist/logging/index.d.ts +1 -1
- package/dist/logging/index.js +1 -3
- package/dist/router/index.cjs +47 -33
- package/dist/router/index.cjs.map +1 -1
- package/dist/router/index.d.cts +6 -6
- package/dist/router/index.d.ts +6 -6
- package/dist/router/index.js +2 -3
- package/dist/{services-3f99f5d2.d.ts → services-fd8a9894.d.ts} +2 -2
- package/dist/transport/impls/uds/client.cjs +195 -81
- package/dist/transport/impls/uds/client.cjs.map +1 -1
- package/dist/transport/impls/uds/client.d.cts +3 -3
- package/dist/transport/impls/uds/client.d.ts +3 -3
- package/dist/transport/impls/uds/client.js +5 -7
- package/dist/transport/impls/uds/client.js.map +1 -1
- package/dist/transport/impls/uds/server.cjs +170 -73
- package/dist/transport/impls/uds/server.cjs.map +1 -1
- package/dist/transport/impls/uds/server.d.cts +3 -3
- package/dist/transport/impls/uds/server.d.ts +3 -3
- package/dist/transport/impls/uds/server.js +4 -4
- package/dist/transport/impls/ws/client.cjs +194 -80
- package/dist/transport/impls/ws/client.cjs.map +1 -1
- package/dist/transport/impls/ws/client.d.cts +3 -3
- package/dist/transport/impls/ws/client.d.ts +3 -3
- package/dist/transport/impls/ws/client.js +6 -8
- package/dist/transport/impls/ws/client.js.map +1 -1
- package/dist/transport/impls/ws/server.cjs +170 -73
- package/dist/transport/impls/ws/server.cjs.map +1 -1
- package/dist/transport/impls/ws/server.d.cts +3 -3
- package/dist/transport/impls/ws/server.d.ts +3 -3
- package/dist/transport/impls/ws/server.js +4 -4
- package/dist/transport/index.cjs +219 -105
- package/dist/transport/index.cjs.map +1 -1
- package/dist/transport/index.d.cts +2 -2
- package/dist/transport/index.d.ts +2 -2
- package/dist/transport/index.js +3 -3
- package/dist/{transport-cbe70659.d.ts → transport-3d34f714.d.ts} +11 -6
- package/dist/util/testHelpers.cjs +27 -18
- package/dist/util/testHelpers.cjs.map +1 -1
- package/dist/util/testHelpers.d.cts +5 -4
- package/dist/util/testHelpers.d.ts +5 -4
- package/dist/util/testHelpers.js +5 -4
- package/dist/util/testHelpers.js.map +1 -1
- package/package.json +5 -3
- package/dist/chunk-7E53HHNS.js.map +0 -1
- package/dist/chunk-GX2YS7BY.js.map +0 -1
- package/dist/chunk-NB3OHLXB.js.map +0 -1
- /package/dist/{chunk-ZFN6I2GJ.js.map → chunk-2KC75LS4.js.map} +0 -0
- /package/dist/{chunk-NJJYBNYM.js.map → chunk-RLVU5DRX.js.map} +0 -0
|
@@ -11,10 +11,11 @@ import {
|
|
|
11
11
|
handshakeResponseMessage,
|
|
12
12
|
isAck,
|
|
13
13
|
tracing_default
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-MFF6IPBA.js";
|
|
15
15
|
import {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
BaseLogger,
|
|
17
|
+
createLogProxy
|
|
18
|
+
} from "./chunk-6LCL2ZZF.js";
|
|
18
19
|
import {
|
|
19
20
|
NaiveJsonCodec
|
|
20
21
|
} from "./chunk-3AW3IXVD.js";
|
|
@@ -30,6 +31,17 @@ var Connection = class {
|
|
|
30
31
|
constructor() {
|
|
31
32
|
this.id = `conn-${nanoid(12)}`;
|
|
32
33
|
}
|
|
34
|
+
get loggingMetadata() {
|
|
35
|
+
const metadata = { connId: this.id };
|
|
36
|
+
const spanContext = this.telemetry?.span.spanContext();
|
|
37
|
+
if (spanContext) {
|
|
38
|
+
metadata.telemetry = {
|
|
39
|
+
traceId: spanContext.traceId,
|
|
40
|
+
spanId: spanContext.spanId
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return metadata;
|
|
44
|
+
}
|
|
33
45
|
};
|
|
34
46
|
var Session = class {
|
|
35
47
|
codec;
|
|
@@ -75,6 +87,7 @@ var Session = class {
|
|
|
75
87
|
* The interval for sending heartbeats.
|
|
76
88
|
*/
|
|
77
89
|
heartbeat;
|
|
90
|
+
log;
|
|
78
91
|
constructor(conn, from, to, options, propagationCtx) {
|
|
79
92
|
this.id = `session-${nanoid(12)}`;
|
|
80
93
|
this.options = options;
|
|
@@ -89,12 +102,20 @@ var Session = class {
|
|
|
89
102
|
);
|
|
90
103
|
this.telemetry = createSessionTelemetryInfo(this, propagationCtx);
|
|
91
104
|
}
|
|
105
|
+
bindLogger(log) {
|
|
106
|
+
this.log = log;
|
|
107
|
+
}
|
|
92
108
|
get loggingMetadata() {
|
|
109
|
+
const spanContext = this.telemetry.span.spanContext();
|
|
93
110
|
return {
|
|
94
111
|
clientId: this.from,
|
|
95
112
|
connectedTo: this.to,
|
|
96
113
|
sessionId: this.id,
|
|
97
|
-
connId: this.connection?.id
|
|
114
|
+
connId: this.connection?.id,
|
|
115
|
+
telemetry: {
|
|
116
|
+
traceId: spanContext.traceId,
|
|
117
|
+
spanId: spanContext.spanId
|
|
118
|
+
}
|
|
98
119
|
};
|
|
99
120
|
}
|
|
100
121
|
/**
|
|
@@ -107,7 +128,7 @@ var Session = class {
|
|
|
107
128
|
*/
|
|
108
129
|
send(msg) {
|
|
109
130
|
const fullMsg = this.constructMsg(msg);
|
|
110
|
-
log?.debug(`sending msg`, {
|
|
131
|
+
this.log?.debug(`sending msg`, {
|
|
111
132
|
...this.loggingMetadata,
|
|
112
133
|
transportMessage: fullMsg
|
|
113
134
|
});
|
|
@@ -115,7 +136,7 @@ var Session = class {
|
|
|
115
136
|
const ok = this.connection.send(this.codec.toBuffer(fullMsg));
|
|
116
137
|
if (ok)
|
|
117
138
|
return fullMsg.id;
|
|
118
|
-
log?.info(
|
|
139
|
+
this.log?.info(
|
|
119
140
|
`failed to send msg to ${fullMsg.to}, connection is probably dead`,
|
|
120
141
|
{
|
|
121
142
|
...this.loggingMetadata,
|
|
@@ -123,8 +144,8 @@ var Session = class {
|
|
|
123
144
|
}
|
|
124
145
|
);
|
|
125
146
|
} else {
|
|
126
|
-
log?.
|
|
127
|
-
`
|
|
147
|
+
this.log?.debug(
|
|
148
|
+
`buffering msg to ${fullMsg.to}, connection not ready yet`,
|
|
128
149
|
{ ...this.loggingMetadata, transportMessage: fullMsg }
|
|
129
150
|
);
|
|
130
151
|
}
|
|
@@ -135,7 +156,7 @@ var Session = class {
|
|
|
135
156
|
const missDuration = misses * this.options.heartbeatIntervalMs;
|
|
136
157
|
if (misses > this.options.heartbeatsUntilDead) {
|
|
137
158
|
if (this.connection) {
|
|
138
|
-
log?.info(
|
|
159
|
+
this.log?.info(
|
|
139
160
|
`closing connection to ${this.to} due to inactivity (missed ${misses} heartbeats which is ${missDuration}ms)`,
|
|
140
161
|
this.loggingMetadata
|
|
141
162
|
);
|
|
@@ -159,12 +180,12 @@ var Session = class {
|
|
|
159
180
|
this.ack = 0;
|
|
160
181
|
}
|
|
161
182
|
sendBufferedMessages(conn) {
|
|
162
|
-
log?.info(`resending ${this.sendBuffer.length} buffered messages`, {
|
|
183
|
+
this.log?.info(`resending ${this.sendBuffer.length} buffered messages`, {
|
|
163
184
|
...this.loggingMetadata,
|
|
164
185
|
connId: conn.id
|
|
165
186
|
});
|
|
166
187
|
for (const msg of this.sendBuffer) {
|
|
167
|
-
log?.debug(`resending msg`, {
|
|
188
|
+
this.log?.debug(`resending msg`, {
|
|
168
189
|
...this.loggingMetadata,
|
|
169
190
|
transportMessage: msg,
|
|
170
191
|
connId: conn.id
|
|
@@ -176,7 +197,7 @@ var Session = class {
|
|
|
176
197
|
code: SpanStatusCode.ERROR,
|
|
177
198
|
message: errMsg
|
|
178
199
|
});
|
|
179
|
-
log?.error(errMsg, {
|
|
200
|
+
this.log?.error(errMsg, {
|
|
180
201
|
...this.loggingMetadata,
|
|
181
202
|
transportMessage: msg,
|
|
182
203
|
connId: conn.id,
|
|
@@ -189,7 +210,7 @@ var Session = class {
|
|
|
189
210
|
}
|
|
190
211
|
updateBookkeeping(ack, seq) {
|
|
191
212
|
if (seq + 1 < this.ack) {
|
|
192
|
-
log?.error(`received stale seq ${seq} + 1 < ${this.ack}`, {
|
|
213
|
+
this.log?.error(`received stale seq ${seq} + 1 < ${this.ack}`, {
|
|
193
214
|
...this.loggingMetadata,
|
|
194
215
|
tags: ["invariant-violation"]
|
|
195
216
|
});
|
|
@@ -201,7 +222,7 @@ var Session = class {
|
|
|
201
222
|
closeStaleConnection(conn) {
|
|
202
223
|
if (this.connection === void 0 || this.connection === conn)
|
|
203
224
|
return;
|
|
204
|
-
log?.info(
|
|
225
|
+
this.log?.info(
|
|
205
226
|
`closing old inner connection from session to ${this.to}`,
|
|
206
227
|
this.loggingMetadata
|
|
207
228
|
);
|
|
@@ -215,7 +236,7 @@ var Session = class {
|
|
|
215
236
|
this.connection = newConn;
|
|
216
237
|
}
|
|
217
238
|
beginGrace(cb) {
|
|
218
|
-
log?.info(
|
|
239
|
+
this.log?.info(
|
|
219
240
|
`starting ${this.options.sessionDisconnectGraceMs}ms grace period until session to ${this.to} is closed`,
|
|
220
241
|
this.loggingMetadata
|
|
221
242
|
);
|
|
@@ -426,6 +447,7 @@ var Transport = class {
|
|
|
426
447
|
* The options for this transport.
|
|
427
448
|
*/
|
|
428
449
|
options;
|
|
450
|
+
log;
|
|
429
451
|
/**
|
|
430
452
|
* Creates a new Transport instance.
|
|
431
453
|
* This should also set up {@link onConnect}, and {@link onDisconnect} listeners.
|
|
@@ -440,6 +462,13 @@ var Transport = class {
|
|
|
440
462
|
this.clientId = clientId;
|
|
441
463
|
this.state = "open";
|
|
442
464
|
}
|
|
465
|
+
bindLogger(fn, level) {
|
|
466
|
+
if (typeof fn === "function") {
|
|
467
|
+
this.log = createLogProxy(new BaseLogger(fn, level));
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
this.log = createLogProxy(fn);
|
|
471
|
+
}
|
|
443
472
|
/**
|
|
444
473
|
* Called when a new connection is established
|
|
445
474
|
* and we know the identity of the connected client.
|
|
@@ -450,13 +479,15 @@ var Transport = class {
|
|
|
450
479
|
status: "connect",
|
|
451
480
|
conn
|
|
452
481
|
});
|
|
453
|
-
conn.telemetry = createConnectionTelemetryInfo(
|
|
454
|
-
conn,
|
|
455
|
-
session.telemetry.span
|
|
456
|
-
);
|
|
482
|
+
conn.telemetry = createConnectionTelemetryInfo(conn, session.telemetry);
|
|
457
483
|
if (isReconnect) {
|
|
458
484
|
session.replaceWithNewConnection(conn);
|
|
459
|
-
log?.info(`reconnected to ${connectedTo}`,
|
|
485
|
+
this.log?.info(`reconnected to ${connectedTo}`, {
|
|
486
|
+
...conn.loggingMetadata,
|
|
487
|
+
...session.loggingMetadata,
|
|
488
|
+
clientId: this.clientId,
|
|
489
|
+
connectedTo
|
|
490
|
+
});
|
|
460
491
|
}
|
|
461
492
|
}
|
|
462
493
|
createSession(to, conn, propagationCtx) {
|
|
@@ -467,6 +498,9 @@ var Transport = class {
|
|
|
467
498
|
this.options,
|
|
468
499
|
propagationCtx
|
|
469
500
|
);
|
|
501
|
+
if (this.log) {
|
|
502
|
+
session.bindLogger(this.log);
|
|
503
|
+
}
|
|
470
504
|
this.sessions.set(session.to, session);
|
|
471
505
|
this.eventDispatcher.dispatchEvent("sessionStatus", {
|
|
472
506
|
status: "connect",
|
|
@@ -478,7 +512,7 @@ var Transport = class {
|
|
|
478
512
|
let session = this.sessions.get(to);
|
|
479
513
|
let isReconnect = session !== void 0;
|
|
480
514
|
if (session?.advertisedSessionId !== void 0 && sessionId !== void 0 && session.advertisedSessionId !== sessionId) {
|
|
481
|
-
log?.info(
|
|
515
|
+
this.log?.info(
|
|
482
516
|
`session for ${to} already exists but has a different session id (expected: ${session.advertisedSessionId}, got: ${sessionId}), creating a new one`,
|
|
483
517
|
session.loggingMetadata
|
|
484
518
|
);
|
|
@@ -488,7 +522,7 @@ var Transport = class {
|
|
|
488
522
|
}
|
|
489
523
|
if (!session) {
|
|
490
524
|
session = this.createSession(to, conn, propagationCtx);
|
|
491
|
-
log?.info(
|
|
525
|
+
this.log?.info(
|
|
492
526
|
`no session for ${to}, created a new one`,
|
|
493
527
|
session.loggingMetadata
|
|
494
528
|
);
|
|
@@ -502,7 +536,7 @@ var Transport = class {
|
|
|
502
536
|
session.close();
|
|
503
537
|
session.telemetry.span.end();
|
|
504
538
|
this.sessions.delete(session.to);
|
|
505
|
-
log?.info(
|
|
539
|
+
this.log?.info(
|
|
506
540
|
`session ${session.id} disconnect from ${session.to}`,
|
|
507
541
|
session.loggingMetadata
|
|
508
542
|
);
|
|
@@ -533,18 +567,23 @@ var Transport = class {
|
|
|
533
567
|
* @param msg The message to parse.
|
|
534
568
|
* @returns The parsed message, or null if the message is malformed or invalid.
|
|
535
569
|
*/
|
|
536
|
-
parseMsg(msg) {
|
|
570
|
+
parseMsg(msg, conn) {
|
|
537
571
|
const parsedMsg = this.codec.fromBuffer(msg);
|
|
538
572
|
if (parsedMsg === null) {
|
|
539
573
|
const decodedBuffer = new TextDecoder().decode(Buffer.from(msg));
|
|
540
|
-
log?.error(
|
|
541
|
-
|
|
542
|
-
|
|
574
|
+
this.log?.error(
|
|
575
|
+
`received malformed msg, killing conn: ${decodedBuffer}`,
|
|
576
|
+
{
|
|
577
|
+
clientId: this.clientId,
|
|
578
|
+
...conn.loggingMetadata
|
|
579
|
+
}
|
|
580
|
+
);
|
|
543
581
|
return null;
|
|
544
582
|
}
|
|
545
583
|
if (!Value.Check(OpaqueTransportMessageSchema, parsedMsg)) {
|
|
546
|
-
log?.error(`received invalid msg: ${JSON.stringify(parsedMsg)}`, {
|
|
584
|
+
this.log?.error(`received invalid msg: ${JSON.stringify(parsedMsg)}`, {
|
|
547
585
|
clientId: this.clientId,
|
|
586
|
+
...conn.loggingMetadata,
|
|
548
587
|
validationErrors: [
|
|
549
588
|
...Value.Errors(OpaqueTransportMessageSchema, parsedMsg)
|
|
550
589
|
]
|
|
@@ -558,34 +597,41 @@ var Transport = class {
|
|
|
558
597
|
* You generally shouldn't need to override this in downstream transport implementations.
|
|
559
598
|
* @param msg The received message.
|
|
560
599
|
*/
|
|
561
|
-
handleMsg(msg) {
|
|
600
|
+
handleMsg(msg, conn) {
|
|
562
601
|
if (this.state !== "open")
|
|
563
602
|
return;
|
|
564
603
|
const session = this.sessions.get(msg.from);
|
|
565
604
|
if (!session) {
|
|
566
|
-
log?.error(`
|
|
605
|
+
this.log?.error(`received message for unknown session from ${msg.from}`, {
|
|
567
606
|
clientId: this.clientId,
|
|
568
607
|
transportMessage: msg,
|
|
608
|
+
...conn.loggingMetadata,
|
|
569
609
|
tags: ["invariant-violation"]
|
|
570
610
|
});
|
|
571
611
|
return;
|
|
572
612
|
}
|
|
573
613
|
session.cancelGrace();
|
|
574
|
-
log?.debug(`received msg`, {
|
|
614
|
+
this.log?.debug(`received msg`, {
|
|
575
615
|
clientId: this.clientId,
|
|
576
|
-
transportMessage: msg
|
|
616
|
+
transportMessage: msg,
|
|
617
|
+
...conn.loggingMetadata
|
|
577
618
|
});
|
|
578
619
|
if (msg.seq !== session.nextExpectedSeq) {
|
|
579
620
|
if (msg.seq < session.nextExpectedSeq) {
|
|
580
|
-
log?.debug(
|
|
621
|
+
this.log?.debug(
|
|
581
622
|
`received duplicate msg (got seq: ${msg.seq}, wanted seq: ${session.nextExpectedSeq}), discarding`,
|
|
582
|
-
{
|
|
623
|
+
{
|
|
624
|
+
clientId: this.clientId,
|
|
625
|
+
transportMessage: msg,
|
|
626
|
+
...conn.loggingMetadata
|
|
627
|
+
}
|
|
583
628
|
);
|
|
584
629
|
} else {
|
|
585
630
|
const errMsg = `received out-of-order msg (got seq: ${msg.seq}, wanted seq: ${session.nextExpectedSeq})`;
|
|
586
|
-
log?.error(`${errMsg}, marking connection as dead`, {
|
|
631
|
+
this.log?.error(`${errMsg}, marking connection as dead`, {
|
|
587
632
|
clientId: this.clientId,
|
|
588
633
|
transportMessage: msg,
|
|
634
|
+
...conn.loggingMetadata,
|
|
589
635
|
tags: ["invariant-violation"]
|
|
590
636
|
});
|
|
591
637
|
this.protocolError(ProtocolError.MessageOrderingViolated, errMsg);
|
|
@@ -601,9 +647,10 @@ var Transport = class {
|
|
|
601
647
|
if (!isAck(msg.controlFlags)) {
|
|
602
648
|
this.eventDispatcher.dispatchEvent("message", msg);
|
|
603
649
|
} else {
|
|
604
|
-
log?.debug(`discarding msg (ack bit set)`, {
|
|
650
|
+
this.log?.debug(`discarding msg (ack bit set)`, {
|
|
605
651
|
clientId: this.clientId,
|
|
606
|
-
transportMessage: msg
|
|
652
|
+
transportMessage: msg,
|
|
653
|
+
...conn.loggingMetadata
|
|
607
654
|
});
|
|
608
655
|
}
|
|
609
656
|
}
|
|
@@ -632,7 +679,7 @@ var Transport = class {
|
|
|
632
679
|
send(to, msg) {
|
|
633
680
|
if (this.state === "destroyed") {
|
|
634
681
|
const err = "transport is destroyed, cant send";
|
|
635
|
-
log?.error(err, {
|
|
682
|
+
this.log?.error(err, {
|
|
636
683
|
clientId: this.clientId,
|
|
637
684
|
transportMessage: msg,
|
|
638
685
|
tags: ["invariant-violation"]
|
|
@@ -640,7 +687,7 @@ var Transport = class {
|
|
|
640
687
|
this.protocolError(ProtocolError.UseAfterDestroy, err);
|
|
641
688
|
return void 0;
|
|
642
689
|
} else if (this.state === "closed") {
|
|
643
|
-
log?.info(`transport closed when sending, discarding`, {
|
|
690
|
+
this.log?.info(`transport closed when sending, discarding`, {
|
|
644
691
|
clientId: this.clientId,
|
|
645
692
|
transportMessage: msg
|
|
646
693
|
});
|
|
@@ -671,7 +718,7 @@ var Transport = class {
|
|
|
671
718
|
for (const session of this.sessions.values()) {
|
|
672
719
|
this.deleteSession(session);
|
|
673
720
|
}
|
|
674
|
-
log?.info(`manually closed transport`, { clientId: this.clientId });
|
|
721
|
+
this.log?.info(`manually closed transport`, { clientId: this.clientId });
|
|
675
722
|
}
|
|
676
723
|
/**
|
|
677
724
|
* Default destroy implementation for transports. You should override this in the downstream
|
|
@@ -683,7 +730,7 @@ var Transport = class {
|
|
|
683
730
|
for (const session of this.sessions.values()) {
|
|
684
731
|
this.deleteSession(session);
|
|
685
732
|
}
|
|
686
|
-
log?.info(`manually destroyed transport`, { clientId: this.clientId });
|
|
733
|
+
this.log?.info(`manually destroyed transport`, { clientId: this.clientId });
|
|
687
734
|
}
|
|
688
735
|
};
|
|
689
736
|
var ClientTransport = class extends Transport {
|
|
@@ -725,9 +772,9 @@ var ClientTransport = class extends Transport {
|
|
|
725
772
|
let session = void 0;
|
|
726
773
|
const handshakeTimeout = setTimeout(() => {
|
|
727
774
|
if (!session) {
|
|
728
|
-
log?.warn(
|
|
775
|
+
this.log?.warn(
|
|
729
776
|
`connection to ${to} timed out waiting for handshake, closing`,
|
|
730
|
-
{ clientId: this.clientId, connectedTo: to
|
|
777
|
+
{ ...conn.loggingMetadata, clientId: this.clientId, connectedTo: to }
|
|
731
778
|
);
|
|
732
779
|
conn.close();
|
|
733
780
|
}
|
|
@@ -743,7 +790,7 @@ var ClientTransport = class extends Transport {
|
|
|
743
790
|
}
|
|
744
791
|
conn.removeDataListener(handshakeHandler);
|
|
745
792
|
conn.addDataListener((data2) => {
|
|
746
|
-
const parsed = this.parseMsg(data2);
|
|
793
|
+
const parsed = this.parseMsg(data2, conn);
|
|
747
794
|
if (!parsed) {
|
|
748
795
|
conn.telemetry?.span.setStatus({
|
|
749
796
|
code: SpanStatusCode2.ERROR,
|
|
@@ -752,7 +799,7 @@ var ClientTransport = class extends Transport {
|
|
|
752
799
|
conn.close();
|
|
753
800
|
return;
|
|
754
801
|
}
|
|
755
|
-
this.handleMsg(parsed);
|
|
802
|
+
this.handleMsg(parsed, conn);
|
|
756
803
|
});
|
|
757
804
|
};
|
|
758
805
|
conn.addDataListener(handshakeHandler);
|
|
@@ -760,7 +807,8 @@ var ClientTransport = class extends Transport {
|
|
|
760
807
|
if (session) {
|
|
761
808
|
this.onDisconnect(conn, session);
|
|
762
809
|
}
|
|
763
|
-
log?.info(`connection to ${to} disconnected`, {
|
|
810
|
+
this.log?.info(`connection to ${to} disconnected`, {
|
|
811
|
+
...conn.loggingMetadata,
|
|
764
812
|
...session?.loggingMetadata,
|
|
765
813
|
clientId: this.clientId,
|
|
766
814
|
connectedTo: to
|
|
@@ -775,15 +823,19 @@ var ClientTransport = class extends Transport {
|
|
|
775
823
|
code: SpanStatusCode2.ERROR,
|
|
776
824
|
message: "connection error"
|
|
777
825
|
});
|
|
778
|
-
log?.warn(
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
826
|
+
this.log?.warn(
|
|
827
|
+
`error in connection to ${to}: ${coerceErrorString(err)}`,
|
|
828
|
+
{
|
|
829
|
+
...conn.loggingMetadata,
|
|
830
|
+
...session?.loggingMetadata,
|
|
831
|
+
clientId: this.clientId,
|
|
832
|
+
connectedTo: to
|
|
833
|
+
}
|
|
834
|
+
);
|
|
783
835
|
});
|
|
784
836
|
}
|
|
785
837
|
receiveHandshakeResponseMessage(data, conn) {
|
|
786
|
-
const parsed = this.parseMsg(data);
|
|
838
|
+
const parsed = this.parseMsg(data, conn);
|
|
787
839
|
if (!parsed) {
|
|
788
840
|
conn.telemetry?.span.setStatus({
|
|
789
841
|
code: SpanStatusCode2.ERROR,
|
|
@@ -800,7 +852,8 @@ var ClientTransport = class extends Transport {
|
|
|
800
852
|
code: SpanStatusCode2.ERROR,
|
|
801
853
|
message: "invalid handshake response"
|
|
802
854
|
});
|
|
803
|
-
log?.warn(`received invalid handshake resp`, {
|
|
855
|
+
this.log?.warn(`received invalid handshake resp`, {
|
|
856
|
+
...conn.loggingMetadata,
|
|
804
857
|
clientId: this.clientId,
|
|
805
858
|
connectedTo: parsed.from,
|
|
806
859
|
transportMessage: parsed,
|
|
@@ -822,7 +875,8 @@ var ClientTransport = class extends Transport {
|
|
|
822
875
|
code: SpanStatusCode2.ERROR,
|
|
823
876
|
message: "handshake rejected"
|
|
824
877
|
});
|
|
825
|
-
log?.warn(`received handshake rejection`, {
|
|
878
|
+
this.log?.warn(`received handshake rejection`, {
|
|
879
|
+
...conn.loggingMetadata,
|
|
826
880
|
clientId: this.clientId,
|
|
827
881
|
connectedTo: parsed.from,
|
|
828
882
|
transportMessage: parsed
|
|
@@ -833,7 +887,8 @@ var ClientTransport = class extends Transport {
|
|
|
833
887
|
);
|
|
834
888
|
return false;
|
|
835
889
|
}
|
|
836
|
-
log?.debug(`handshake from ${parsed.from} ok`, {
|
|
890
|
+
this.log?.debug(`handshake from ${parsed.from} ok`, {
|
|
891
|
+
...conn.loggingMetadata,
|
|
837
892
|
clientId: this.clientId,
|
|
838
893
|
connectedTo: parsed.from,
|
|
839
894
|
transportMessage: parsed
|
|
@@ -854,7 +909,7 @@ var ClientTransport = class extends Transport {
|
|
|
854
909
|
async connect(to) {
|
|
855
910
|
const canProceedWithConnection = () => this.state === "open";
|
|
856
911
|
if (!canProceedWithConnection()) {
|
|
857
|
-
log?.info(
|
|
912
|
+
this.log?.info(
|
|
858
913
|
`transport state is no longer open, cancelling attempt to connect to ${to}`,
|
|
859
914
|
{ clientId: this.clientId, connectedTo: to }
|
|
860
915
|
);
|
|
@@ -865,7 +920,7 @@ var ClientTransport = class extends Transport {
|
|
|
865
920
|
const budgetConsumed = this.retryBudget.getBudgetConsumed(to);
|
|
866
921
|
if (!this.retryBudget.hasBudget(to)) {
|
|
867
922
|
const errMsg = `tried to connect to ${to} but retry budget exceeded (more than ${budgetConsumed} attempts in the last ${this.retryBudget.totalBudgetRestoreTime}ms)`;
|
|
868
|
-
log?.
|
|
923
|
+
this.log?.error(errMsg, { clientId: this.clientId, connectedTo: to });
|
|
869
924
|
this.protocolError(ProtocolError.RetriesExceeded, errMsg);
|
|
870
925
|
return;
|
|
871
926
|
}
|
|
@@ -874,10 +929,13 @@ var ClientTransport = class extends Transport {
|
|
|
874
929
|
if (backoffMs > 0) {
|
|
875
930
|
sleep = new Promise((resolve) => setTimeout(resolve, backoffMs));
|
|
876
931
|
}
|
|
877
|
-
log?.info(
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
932
|
+
this.log?.info(
|
|
933
|
+
`attempting connection to ${to} (${backoffMs}ms backoff)`,
|
|
934
|
+
{
|
|
935
|
+
clientId: this.clientId,
|
|
936
|
+
connectedTo: to
|
|
937
|
+
}
|
|
938
|
+
);
|
|
881
939
|
this.retryBudget.consumeBudget(to);
|
|
882
940
|
reconnectPromise = tracing_default.startActiveSpan("connect", async (span) => {
|
|
883
941
|
try {
|
|
@@ -889,12 +947,12 @@ var ClientTransport = class extends Transport {
|
|
|
889
947
|
span.addEvent("connecting");
|
|
890
948
|
const conn = await this.createNewOutgoingConnection(to);
|
|
891
949
|
if (!canProceedWithConnection()) {
|
|
892
|
-
log?.info(
|
|
950
|
+
this.log?.info(
|
|
893
951
|
`transport state is no longer open, closing pre-handshake connection to ${to}`,
|
|
894
952
|
{
|
|
953
|
+
...conn.loggingMetadata,
|
|
895
954
|
clientId: this.clientId,
|
|
896
|
-
connectedTo: to
|
|
897
|
-
connId: conn.id
|
|
955
|
+
connectedTo: to
|
|
898
956
|
}
|
|
899
957
|
);
|
|
900
958
|
conn.close();
|
|
@@ -918,10 +976,13 @@ var ClientTransport = class extends Transport {
|
|
|
918
976
|
});
|
|
919
977
|
this.inflightConnectionPromises.set(to, reconnectPromise);
|
|
920
978
|
} else {
|
|
921
|
-
log?.info(
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
979
|
+
this.log?.info(
|
|
980
|
+
`attempting connection to ${to} (reusing previous attempt)`,
|
|
981
|
+
{
|
|
982
|
+
clientId: this.clientId,
|
|
983
|
+
connectedTo: to
|
|
984
|
+
}
|
|
985
|
+
);
|
|
925
986
|
}
|
|
926
987
|
try {
|
|
927
988
|
await reconnectPromise;
|
|
@@ -929,12 +990,12 @@ var ClientTransport = class extends Transport {
|
|
|
929
990
|
this.inflightConnectionPromises.delete(to);
|
|
930
991
|
const errStr = coerceErrorString(error);
|
|
931
992
|
if (!this.reconnectOnConnectionDrop || !canProceedWithConnection()) {
|
|
932
|
-
log?.warn(`connection to ${to} failed (${errStr})`, {
|
|
993
|
+
this.log?.warn(`connection to ${to} failed (${errStr})`, {
|
|
933
994
|
clientId: this.clientId,
|
|
934
995
|
connectedTo: to
|
|
935
996
|
});
|
|
936
997
|
} else {
|
|
937
|
-
log?.warn(`connection to ${to} failed (${errStr}), retrying`, {
|
|
998
|
+
this.log?.warn(`connection to ${to} failed (${errStr}), retrying`, {
|
|
938
999
|
clientId: this.clientId,
|
|
939
1000
|
connectedTo: to
|
|
940
1001
|
});
|
|
@@ -951,7 +1012,8 @@ var ClientTransport = class extends Transport {
|
|
|
951
1012
|
if (this.handshakeExtensions) {
|
|
952
1013
|
metadata = await this.handshakeExtensions.construct();
|
|
953
1014
|
if (!Value.Check(this.handshakeExtensions.schema, metadata)) {
|
|
954
|
-
log?.error(`constructed handshake metadata did not match schema`, {
|
|
1015
|
+
this.log?.error(`constructed handshake metadata did not match schema`, {
|
|
1016
|
+
...conn.loggingMetadata,
|
|
955
1017
|
clientId: this.clientId,
|
|
956
1018
|
connectedTo: to,
|
|
957
1019
|
validationErrors: [
|
|
@@ -978,9 +1040,11 @@ var ClientTransport = class extends Transport {
|
|
|
978
1040
|
metadata,
|
|
979
1041
|
getPropagationContext(session.telemetry.ctx)
|
|
980
1042
|
);
|
|
981
|
-
log?.debug(`sending handshake request to ${to}`, {
|
|
1043
|
+
this.log?.debug(`sending handshake request to ${to}`, {
|
|
1044
|
+
...conn.loggingMetadata,
|
|
982
1045
|
clientId: this.clientId,
|
|
983
|
-
connectedTo: to
|
|
1046
|
+
connectedTo: to,
|
|
1047
|
+
transportMessage: requestMsg
|
|
984
1048
|
});
|
|
985
1049
|
conn.send(this.codec.toBuffer(requestMsg));
|
|
986
1050
|
return true;
|
|
@@ -1010,7 +1074,7 @@ var ServerTransport = class extends Transport {
|
|
|
1010
1074
|
...providedOptions
|
|
1011
1075
|
};
|
|
1012
1076
|
this.sessionHandshakeMetadata = /* @__PURE__ */ new WeakMap();
|
|
1013
|
-
log?.info(`initiated server transport`, {
|
|
1077
|
+
this.log?.info(`initiated server transport`, {
|
|
1014
1078
|
clientId: this.clientId,
|
|
1015
1079
|
protocolVersion: PROTOCOL_VERSION
|
|
1016
1080
|
});
|
|
@@ -1021,20 +1085,20 @@ var ServerTransport = class extends Transport {
|
|
|
1021
1085
|
handleConnection(conn) {
|
|
1022
1086
|
if (this.state !== "open")
|
|
1023
1087
|
return;
|
|
1024
|
-
log?.info(`new incoming connection`, {
|
|
1025
|
-
|
|
1026
|
-
|
|
1088
|
+
this.log?.info(`new incoming connection`, {
|
|
1089
|
+
...conn.loggingMetadata,
|
|
1090
|
+
clientId: this.clientId
|
|
1027
1091
|
});
|
|
1028
1092
|
let session = void 0;
|
|
1029
1093
|
const client = () => session?.to ?? "unknown";
|
|
1030
1094
|
const handshakeTimeout = setTimeout(() => {
|
|
1031
1095
|
if (!session) {
|
|
1032
|
-
log?.warn(
|
|
1096
|
+
this.log?.warn(
|
|
1033
1097
|
`connection to ${client()} timed out waiting for handshake, closing`,
|
|
1034
1098
|
{
|
|
1099
|
+
...conn.loggingMetadata,
|
|
1035
1100
|
clientId: this.clientId,
|
|
1036
|
-
connectedTo: client()
|
|
1037
|
-
connId: conn.id
|
|
1101
|
+
connectedTo: client()
|
|
1038
1102
|
}
|
|
1039
1103
|
);
|
|
1040
1104
|
conn.telemetry?.span.setStatus({
|
|
@@ -1061,12 +1125,12 @@ var ServerTransport = class extends Transport {
|
|
|
1061
1125
|
}
|
|
1062
1126
|
session = maybeSession;
|
|
1063
1127
|
const dataHandler = (data2) => {
|
|
1064
|
-
const parsed = this.parseMsg(data2);
|
|
1128
|
+
const parsed = this.parseMsg(data2, conn);
|
|
1065
1129
|
if (!parsed) {
|
|
1066
1130
|
conn.close();
|
|
1067
1131
|
return;
|
|
1068
1132
|
}
|
|
1069
|
-
this.handleMsg(parsed);
|
|
1133
|
+
this.handleMsg(parsed, conn);
|
|
1070
1134
|
};
|
|
1071
1135
|
for (const data2 of buffer) {
|
|
1072
1136
|
dataHandler(data2);
|
|
@@ -1081,9 +1145,9 @@ var ServerTransport = class extends Transport {
|
|
|
1081
1145
|
conn.addCloseListener(() => {
|
|
1082
1146
|
if (!session)
|
|
1083
1147
|
return;
|
|
1084
|
-
log?.info(`connection to ${client()} disconnected`, {
|
|
1085
|
-
|
|
1086
|
-
|
|
1148
|
+
this.log?.info(`connection to ${client()} disconnected`, {
|
|
1149
|
+
...conn.loggingMetadata,
|
|
1150
|
+
clientId: this.clientId
|
|
1087
1151
|
});
|
|
1088
1152
|
this.onDisconnect(conn, session);
|
|
1089
1153
|
});
|
|
@@ -1094,9 +1158,9 @@ var ServerTransport = class extends Transport {
|
|
|
1094
1158
|
});
|
|
1095
1159
|
if (!session)
|
|
1096
1160
|
return;
|
|
1097
|
-
log?.warn(
|
|
1161
|
+
this.log?.warn(
|
|
1098
1162
|
`connection to ${client()} got an error: ${coerceErrorString(err)}`,
|
|
1099
|
-
{ clientId: this.clientId
|
|
1163
|
+
{ ...conn.loggingMetadata, clientId: this.clientId }
|
|
1100
1164
|
);
|
|
1101
1165
|
});
|
|
1102
1166
|
}
|
|
@@ -1114,9 +1178,9 @@ var ServerTransport = class extends Transport {
|
|
|
1114
1178
|
reason
|
|
1115
1179
|
});
|
|
1116
1180
|
conn.send(this.codec.toBuffer(responseMsg));
|
|
1117
|
-
log?.warn(`received malformed handshake metadata from ${from}`, {
|
|
1181
|
+
this.log?.warn(`received malformed handshake metadata from ${from}`, {
|
|
1182
|
+
...conn.loggingMetadata,
|
|
1118
1183
|
clientId: this.clientId,
|
|
1119
|
-
connId: conn.id,
|
|
1120
1184
|
validationErrors: [
|
|
1121
1185
|
...Value.Errors(this.handshakeExtensions.schema, rawMetadata)
|
|
1122
1186
|
]
|
|
@@ -1140,9 +1204,9 @@ var ServerTransport = class extends Transport {
|
|
|
1140
1204
|
reason
|
|
1141
1205
|
});
|
|
1142
1206
|
conn.send(this.codec.toBuffer(responseMsg));
|
|
1143
|
-
log?.warn(`rejected handshake from ${from}`, {
|
|
1144
|
-
|
|
1145
|
-
|
|
1207
|
+
this.log?.warn(`rejected handshake from ${from}`, {
|
|
1208
|
+
...conn.loggingMetadata,
|
|
1209
|
+
clientId: this.clientId
|
|
1146
1210
|
});
|
|
1147
1211
|
this.protocolError(ProtocolError.HandshakeFailed, reason);
|
|
1148
1212
|
return false;
|
|
@@ -1151,7 +1215,7 @@ var ServerTransport = class extends Transport {
|
|
|
1151
1215
|
return parsedMetadata;
|
|
1152
1216
|
}
|
|
1153
1217
|
async receiveHandshakeRequestMessage(data, conn) {
|
|
1154
|
-
const parsed = this.parseMsg(data);
|
|
1218
|
+
const parsed = this.parseMsg(data, conn);
|
|
1155
1219
|
if (!parsed) {
|
|
1156
1220
|
conn.telemetry?.span.setStatus({
|
|
1157
1221
|
code: SpanStatusCode2.ERROR,
|
|
@@ -1174,10 +1238,10 @@ var ServerTransport = class extends Transport {
|
|
|
1174
1238
|
reason
|
|
1175
1239
|
});
|
|
1176
1240
|
conn.send(this.codec.toBuffer(responseMsg2));
|
|
1177
|
-
log?.warn(reason, {
|
|
1241
|
+
this.log?.warn(reason, {
|
|
1242
|
+
...conn.loggingMetadata,
|
|
1178
1243
|
clientId: this.clientId,
|
|
1179
|
-
|
|
1180
|
-
// safe to log metadata here as we remove the payload
|
|
1244
|
+
// safe to this.log metadata here as we remove the payload
|
|
1181
1245
|
// before passing it to user-land
|
|
1182
1246
|
transportMessage: parsed,
|
|
1183
1247
|
validationErrors: [
|
|
@@ -1202,9 +1266,9 @@ var ServerTransport = class extends Transport {
|
|
|
1202
1266
|
reason
|
|
1203
1267
|
});
|
|
1204
1268
|
conn.send(this.codec.toBuffer(responseMsg2));
|
|
1205
|
-
log?.warn(
|
|
1269
|
+
this.log?.warn(
|
|
1206
1270
|
`received handshake msg with incompatible protocol version (got: ${gotVersion}, expected: ${PROTOCOL_VERSION})`,
|
|
1207
|
-
{ clientId: this.clientId
|
|
1271
|
+
{ ...conn.loggingMetadata, clientId: this.clientId }
|
|
1208
1272
|
);
|
|
1209
1273
|
this.protocolError(ProtocolError.HandshakeFailed, reason);
|
|
1210
1274
|
return false;
|
|
@@ -1226,9 +1290,9 @@ var ServerTransport = class extends Transport {
|
|
|
1226
1290
|
parsed.tracing
|
|
1227
1291
|
);
|
|
1228
1292
|
this.sessionHandshakeMetadata.set(session, parsedMetadata);
|
|
1229
|
-
log?.debug(
|
|
1293
|
+
this.log?.debug(
|
|
1230
1294
|
`handshake from ${parsed.from} ok, responding with handshake success`,
|
|
1231
|
-
|
|
1295
|
+
conn.loggingMetadata
|
|
1232
1296
|
);
|
|
1233
1297
|
const responseMsg = handshakeResponseMessage(this.clientId, parsed.from, {
|
|
1234
1298
|
ok: true,
|
|
@@ -1249,4 +1313,4 @@ export {
|
|
|
1249
1313
|
ClientTransport,
|
|
1250
1314
|
ServerTransport
|
|
1251
1315
|
};
|
|
1252
|
-
//# sourceMappingURL=chunk-
|
|
1316
|
+
//# sourceMappingURL=chunk-XYFXRL7Q.js.map
|