@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
|
@@ -25,9 +25,6 @@ __export(client_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(client_exports);
|
|
26
26
|
var import_node_net = require("net");
|
|
27
27
|
|
|
28
|
-
// logging/log.ts
|
|
29
|
-
var log = void 0;
|
|
30
|
-
|
|
31
28
|
// transport/session.ts
|
|
32
29
|
var import_nanoid2 = require("nanoid");
|
|
33
30
|
|
|
@@ -113,7 +110,7 @@ function isAck(controlFlag) {
|
|
|
113
110
|
var import_api = require("@opentelemetry/api");
|
|
114
111
|
|
|
115
112
|
// package.json
|
|
116
|
-
var version = "0.23.
|
|
113
|
+
var version = "0.23.7";
|
|
117
114
|
|
|
118
115
|
// tracing/index.ts
|
|
119
116
|
function getPropagationContext(ctx) {
|
|
@@ -125,7 +122,7 @@ function getPropagationContext(ctx) {
|
|
|
125
122
|
return tracing;
|
|
126
123
|
}
|
|
127
124
|
function createSessionTelemetryInfo(session, propagationCtx) {
|
|
128
|
-
const
|
|
125
|
+
const parentCtx = propagationCtx ? import_api.propagation.extract(import_api.context.active(), propagationCtx) : import_api.context.active();
|
|
129
126
|
const span = tracer.startSpan(
|
|
130
127
|
`session ${session.id}`,
|
|
131
128
|
{
|
|
@@ -136,12 +133,12 @@ function createSessionTelemetryInfo(session, propagationCtx) {
|
|
|
136
133
|
"river.session.from": session.from
|
|
137
134
|
}
|
|
138
135
|
},
|
|
139
|
-
|
|
136
|
+
parentCtx
|
|
140
137
|
);
|
|
138
|
+
const ctx = import_api.trace.setSpan(parentCtx, span);
|
|
141
139
|
return { span, ctx };
|
|
142
140
|
}
|
|
143
|
-
function createConnectionTelemetryInfo(connection,
|
|
144
|
-
const ctx = import_api.trace.setSpan(import_api.context.active(), sessionSpan);
|
|
141
|
+
function createConnectionTelemetryInfo(connection, info) {
|
|
145
142
|
const span = tracer.startSpan(
|
|
146
143
|
`connection ${connection.id}`,
|
|
147
144
|
{
|
|
@@ -149,10 +146,11 @@ function createConnectionTelemetryInfo(connection, sessionSpan) {
|
|
|
149
146
|
component: "river",
|
|
150
147
|
"river.connection.id": connection.id
|
|
151
148
|
},
|
|
152
|
-
links: [{ context:
|
|
149
|
+
links: [{ context: info.span.spanContext() }]
|
|
153
150
|
},
|
|
154
|
-
ctx
|
|
151
|
+
info.ctx
|
|
155
152
|
);
|
|
153
|
+
const ctx = import_api.trace.setSpan(info.ctx, span);
|
|
156
154
|
return { span, ctx };
|
|
157
155
|
}
|
|
158
156
|
var tracer = import_api.trace.getTracer("river", version);
|
|
@@ -168,6 +166,17 @@ var Connection = class {
|
|
|
168
166
|
constructor() {
|
|
169
167
|
this.id = `conn-${nanoid2(12)}`;
|
|
170
168
|
}
|
|
169
|
+
get loggingMetadata() {
|
|
170
|
+
const metadata = { connId: this.id };
|
|
171
|
+
const spanContext = this.telemetry?.span.spanContext();
|
|
172
|
+
if (spanContext) {
|
|
173
|
+
metadata.telemetry = {
|
|
174
|
+
traceId: spanContext.traceId,
|
|
175
|
+
spanId: spanContext.spanId
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
return metadata;
|
|
179
|
+
}
|
|
171
180
|
};
|
|
172
181
|
var Session = class {
|
|
173
182
|
codec;
|
|
@@ -213,6 +222,7 @@ var Session = class {
|
|
|
213
222
|
* The interval for sending heartbeats.
|
|
214
223
|
*/
|
|
215
224
|
heartbeat;
|
|
225
|
+
log;
|
|
216
226
|
constructor(conn, from, to, options, propagationCtx) {
|
|
217
227
|
this.id = `session-${nanoid2(12)}`;
|
|
218
228
|
this.options = options;
|
|
@@ -227,12 +237,20 @@ var Session = class {
|
|
|
227
237
|
);
|
|
228
238
|
this.telemetry = createSessionTelemetryInfo(this, propagationCtx);
|
|
229
239
|
}
|
|
240
|
+
bindLogger(log) {
|
|
241
|
+
this.log = log;
|
|
242
|
+
}
|
|
230
243
|
get loggingMetadata() {
|
|
244
|
+
const spanContext = this.telemetry.span.spanContext();
|
|
231
245
|
return {
|
|
232
246
|
clientId: this.from,
|
|
233
247
|
connectedTo: this.to,
|
|
234
248
|
sessionId: this.id,
|
|
235
|
-
connId: this.connection?.id
|
|
249
|
+
connId: this.connection?.id,
|
|
250
|
+
telemetry: {
|
|
251
|
+
traceId: spanContext.traceId,
|
|
252
|
+
spanId: spanContext.spanId
|
|
253
|
+
}
|
|
236
254
|
};
|
|
237
255
|
}
|
|
238
256
|
/**
|
|
@@ -245,7 +263,7 @@ var Session = class {
|
|
|
245
263
|
*/
|
|
246
264
|
send(msg) {
|
|
247
265
|
const fullMsg = this.constructMsg(msg);
|
|
248
|
-
log?.debug(`sending msg`, {
|
|
266
|
+
this.log?.debug(`sending msg`, {
|
|
249
267
|
...this.loggingMetadata,
|
|
250
268
|
transportMessage: fullMsg
|
|
251
269
|
});
|
|
@@ -253,7 +271,7 @@ var Session = class {
|
|
|
253
271
|
const ok = this.connection.send(this.codec.toBuffer(fullMsg));
|
|
254
272
|
if (ok)
|
|
255
273
|
return fullMsg.id;
|
|
256
|
-
log?.info(
|
|
274
|
+
this.log?.info(
|
|
257
275
|
`failed to send msg to ${fullMsg.to}, connection is probably dead`,
|
|
258
276
|
{
|
|
259
277
|
...this.loggingMetadata,
|
|
@@ -261,8 +279,8 @@ var Session = class {
|
|
|
261
279
|
}
|
|
262
280
|
);
|
|
263
281
|
} else {
|
|
264
|
-
log?.
|
|
265
|
-
`
|
|
282
|
+
this.log?.debug(
|
|
283
|
+
`buffering msg to ${fullMsg.to}, connection not ready yet`,
|
|
266
284
|
{ ...this.loggingMetadata, transportMessage: fullMsg }
|
|
267
285
|
);
|
|
268
286
|
}
|
|
@@ -273,7 +291,7 @@ var Session = class {
|
|
|
273
291
|
const missDuration = misses * this.options.heartbeatIntervalMs;
|
|
274
292
|
if (misses > this.options.heartbeatsUntilDead) {
|
|
275
293
|
if (this.connection) {
|
|
276
|
-
log?.info(
|
|
294
|
+
this.log?.info(
|
|
277
295
|
`closing connection to ${this.to} due to inactivity (missed ${misses} heartbeats which is ${missDuration}ms)`,
|
|
278
296
|
this.loggingMetadata
|
|
279
297
|
);
|
|
@@ -297,12 +315,12 @@ var Session = class {
|
|
|
297
315
|
this.ack = 0;
|
|
298
316
|
}
|
|
299
317
|
sendBufferedMessages(conn) {
|
|
300
|
-
log?.info(`resending ${this.sendBuffer.length} buffered messages`, {
|
|
318
|
+
this.log?.info(`resending ${this.sendBuffer.length} buffered messages`, {
|
|
301
319
|
...this.loggingMetadata,
|
|
302
320
|
connId: conn.id
|
|
303
321
|
});
|
|
304
322
|
for (const msg of this.sendBuffer) {
|
|
305
|
-
log?.debug(`resending msg`, {
|
|
323
|
+
this.log?.debug(`resending msg`, {
|
|
306
324
|
...this.loggingMetadata,
|
|
307
325
|
transportMessage: msg,
|
|
308
326
|
connId: conn.id
|
|
@@ -314,7 +332,7 @@ var Session = class {
|
|
|
314
332
|
code: import_api2.SpanStatusCode.ERROR,
|
|
315
333
|
message: errMsg
|
|
316
334
|
});
|
|
317
|
-
log?.error(errMsg, {
|
|
335
|
+
this.log?.error(errMsg, {
|
|
318
336
|
...this.loggingMetadata,
|
|
319
337
|
transportMessage: msg,
|
|
320
338
|
connId: conn.id,
|
|
@@ -327,7 +345,7 @@ var Session = class {
|
|
|
327
345
|
}
|
|
328
346
|
updateBookkeeping(ack, seq) {
|
|
329
347
|
if (seq + 1 < this.ack) {
|
|
330
|
-
log?.error(`received stale seq ${seq} + 1 < ${this.ack}`, {
|
|
348
|
+
this.log?.error(`received stale seq ${seq} + 1 < ${this.ack}`, {
|
|
331
349
|
...this.loggingMetadata,
|
|
332
350
|
tags: ["invariant-violation"]
|
|
333
351
|
});
|
|
@@ -339,7 +357,7 @@ var Session = class {
|
|
|
339
357
|
closeStaleConnection(conn) {
|
|
340
358
|
if (this.connection === void 0 || this.connection === conn)
|
|
341
359
|
return;
|
|
342
|
-
log?.info(
|
|
360
|
+
this.log?.info(
|
|
343
361
|
`closing old inner connection from session to ${this.to}`,
|
|
344
362
|
this.loggingMetadata
|
|
345
363
|
);
|
|
@@ -353,7 +371,7 @@ var Session = class {
|
|
|
353
371
|
this.connection = newConn;
|
|
354
372
|
}
|
|
355
373
|
beginGrace(cb) {
|
|
356
|
-
log?.info(
|
|
374
|
+
this.log?.info(
|
|
357
375
|
`starting ${this.options.sessionDisconnectGraceMs}ms grace period until session to ${this.to} is closed`,
|
|
358
376
|
this.loggingMetadata
|
|
359
377
|
);
|
|
@@ -501,6 +519,59 @@ var UdsConnection = class extends Connection {
|
|
|
501
519
|
// transport/transport.ts
|
|
502
520
|
var import_value = require("@sinclair/typebox/value");
|
|
503
521
|
|
|
522
|
+
// logging/log.ts
|
|
523
|
+
var LoggingLevels = {
|
|
524
|
+
debug: -1,
|
|
525
|
+
info: 0,
|
|
526
|
+
warn: 1,
|
|
527
|
+
error: 2
|
|
528
|
+
};
|
|
529
|
+
var cleanedLogFn = (log) => {
|
|
530
|
+
return (msg, metadata) => {
|
|
531
|
+
if (!metadata?.transportMessage) {
|
|
532
|
+
log(msg, metadata);
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
const { payload, ...rest } = metadata.transportMessage;
|
|
536
|
+
metadata.transportMessage = rest;
|
|
537
|
+
log(msg, metadata);
|
|
538
|
+
};
|
|
539
|
+
};
|
|
540
|
+
var BaseLogger = class {
|
|
541
|
+
minLevel;
|
|
542
|
+
output;
|
|
543
|
+
constructor(output, minLevel = "info") {
|
|
544
|
+
this.minLevel = minLevel;
|
|
545
|
+
this.output = output;
|
|
546
|
+
}
|
|
547
|
+
debug(msg, metadata) {
|
|
548
|
+
if (LoggingLevels[this.minLevel] <= LoggingLevels.debug) {
|
|
549
|
+
this.output(msg, metadata ?? {}, "debug");
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
info(msg, metadata) {
|
|
553
|
+
if (LoggingLevels[this.minLevel] <= LoggingLevels.info) {
|
|
554
|
+
this.output(msg, metadata ?? {}, "info");
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
warn(msg, metadata) {
|
|
558
|
+
if (LoggingLevels[this.minLevel] <= LoggingLevels.warn) {
|
|
559
|
+
this.output(msg, metadata ?? {}, "warn");
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
error(msg, metadata) {
|
|
563
|
+
if (LoggingLevels[this.minLevel] <= LoggingLevels.error) {
|
|
564
|
+
this.output(msg, metadata ?? {}, "error");
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
var createLogProxy = (log) => ({
|
|
569
|
+
debug: cleanedLogFn(log.debug.bind(log)),
|
|
570
|
+
info: cleanedLogFn(log.info.bind(log)),
|
|
571
|
+
warn: cleanedLogFn(log.warn.bind(log)),
|
|
572
|
+
error: cleanedLogFn(log.error.bind(log))
|
|
573
|
+
});
|
|
574
|
+
|
|
504
575
|
// transport/events.ts
|
|
505
576
|
var ProtocolError = {
|
|
506
577
|
RetriesExceeded: "conn_retry_exceeded",
|
|
@@ -722,6 +793,7 @@ var Transport = class {
|
|
|
722
793
|
* The options for this transport.
|
|
723
794
|
*/
|
|
724
795
|
options;
|
|
796
|
+
log;
|
|
725
797
|
/**
|
|
726
798
|
* Creates a new Transport instance.
|
|
727
799
|
* This should also set up {@link onConnect}, and {@link onDisconnect} listeners.
|
|
@@ -736,6 +808,13 @@ var Transport = class {
|
|
|
736
808
|
this.clientId = clientId;
|
|
737
809
|
this.state = "open";
|
|
738
810
|
}
|
|
811
|
+
bindLogger(fn, level) {
|
|
812
|
+
if (typeof fn === "function") {
|
|
813
|
+
this.log = createLogProxy(new BaseLogger(fn, level));
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
this.log = createLogProxy(fn);
|
|
817
|
+
}
|
|
739
818
|
/**
|
|
740
819
|
* Called when a new connection is established
|
|
741
820
|
* and we know the identity of the connected client.
|
|
@@ -746,13 +825,15 @@ var Transport = class {
|
|
|
746
825
|
status: "connect",
|
|
747
826
|
conn
|
|
748
827
|
});
|
|
749
|
-
conn.telemetry = createConnectionTelemetryInfo(
|
|
750
|
-
conn,
|
|
751
|
-
session.telemetry.span
|
|
752
|
-
);
|
|
828
|
+
conn.telemetry = createConnectionTelemetryInfo(conn, session.telemetry);
|
|
753
829
|
if (isReconnect) {
|
|
754
830
|
session.replaceWithNewConnection(conn);
|
|
755
|
-
log?.info(`reconnected to ${connectedTo}`,
|
|
831
|
+
this.log?.info(`reconnected to ${connectedTo}`, {
|
|
832
|
+
...conn.loggingMetadata,
|
|
833
|
+
...session.loggingMetadata,
|
|
834
|
+
clientId: this.clientId,
|
|
835
|
+
connectedTo
|
|
836
|
+
});
|
|
756
837
|
}
|
|
757
838
|
}
|
|
758
839
|
createSession(to, conn, propagationCtx) {
|
|
@@ -763,6 +844,9 @@ var Transport = class {
|
|
|
763
844
|
this.options,
|
|
764
845
|
propagationCtx
|
|
765
846
|
);
|
|
847
|
+
if (this.log) {
|
|
848
|
+
session.bindLogger(this.log);
|
|
849
|
+
}
|
|
766
850
|
this.sessions.set(session.to, session);
|
|
767
851
|
this.eventDispatcher.dispatchEvent("sessionStatus", {
|
|
768
852
|
status: "connect",
|
|
@@ -774,7 +858,7 @@ var Transport = class {
|
|
|
774
858
|
let session = this.sessions.get(to);
|
|
775
859
|
let isReconnect = session !== void 0;
|
|
776
860
|
if (session?.advertisedSessionId !== void 0 && sessionId !== void 0 && session.advertisedSessionId !== sessionId) {
|
|
777
|
-
log?.info(
|
|
861
|
+
this.log?.info(
|
|
778
862
|
`session for ${to} already exists but has a different session id (expected: ${session.advertisedSessionId}, got: ${sessionId}), creating a new one`,
|
|
779
863
|
session.loggingMetadata
|
|
780
864
|
);
|
|
@@ -784,7 +868,7 @@ var Transport = class {
|
|
|
784
868
|
}
|
|
785
869
|
if (!session) {
|
|
786
870
|
session = this.createSession(to, conn, propagationCtx);
|
|
787
|
-
log?.info(
|
|
871
|
+
this.log?.info(
|
|
788
872
|
`no session for ${to}, created a new one`,
|
|
789
873
|
session.loggingMetadata
|
|
790
874
|
);
|
|
@@ -798,7 +882,7 @@ var Transport = class {
|
|
|
798
882
|
session.close();
|
|
799
883
|
session.telemetry.span.end();
|
|
800
884
|
this.sessions.delete(session.to);
|
|
801
|
-
log?.info(
|
|
885
|
+
this.log?.info(
|
|
802
886
|
`session ${session.id} disconnect from ${session.to}`,
|
|
803
887
|
session.loggingMetadata
|
|
804
888
|
);
|
|
@@ -829,18 +913,23 @@ var Transport = class {
|
|
|
829
913
|
* @param msg The message to parse.
|
|
830
914
|
* @returns The parsed message, or null if the message is malformed or invalid.
|
|
831
915
|
*/
|
|
832
|
-
parseMsg(msg) {
|
|
916
|
+
parseMsg(msg, conn) {
|
|
833
917
|
const parsedMsg = this.codec.fromBuffer(msg);
|
|
834
918
|
if (parsedMsg === null) {
|
|
835
919
|
const decodedBuffer = new TextDecoder().decode(Buffer.from(msg));
|
|
836
|
-
log?.error(
|
|
837
|
-
|
|
838
|
-
|
|
920
|
+
this.log?.error(
|
|
921
|
+
`received malformed msg, killing conn: ${decodedBuffer}`,
|
|
922
|
+
{
|
|
923
|
+
clientId: this.clientId,
|
|
924
|
+
...conn.loggingMetadata
|
|
925
|
+
}
|
|
926
|
+
);
|
|
839
927
|
return null;
|
|
840
928
|
}
|
|
841
929
|
if (!import_value.Value.Check(OpaqueTransportMessageSchema, parsedMsg)) {
|
|
842
|
-
log?.error(`received invalid msg: ${JSON.stringify(parsedMsg)}`, {
|
|
930
|
+
this.log?.error(`received invalid msg: ${JSON.stringify(parsedMsg)}`, {
|
|
843
931
|
clientId: this.clientId,
|
|
932
|
+
...conn.loggingMetadata,
|
|
844
933
|
validationErrors: [
|
|
845
934
|
...import_value.Value.Errors(OpaqueTransportMessageSchema, parsedMsg)
|
|
846
935
|
]
|
|
@@ -854,34 +943,41 @@ var Transport = class {
|
|
|
854
943
|
* You generally shouldn't need to override this in downstream transport implementations.
|
|
855
944
|
* @param msg The received message.
|
|
856
945
|
*/
|
|
857
|
-
handleMsg(msg) {
|
|
946
|
+
handleMsg(msg, conn) {
|
|
858
947
|
if (this.state !== "open")
|
|
859
948
|
return;
|
|
860
949
|
const session = this.sessions.get(msg.from);
|
|
861
950
|
if (!session) {
|
|
862
|
-
log?.error(`
|
|
951
|
+
this.log?.error(`received message for unknown session from ${msg.from}`, {
|
|
863
952
|
clientId: this.clientId,
|
|
864
953
|
transportMessage: msg,
|
|
954
|
+
...conn.loggingMetadata,
|
|
865
955
|
tags: ["invariant-violation"]
|
|
866
956
|
});
|
|
867
957
|
return;
|
|
868
958
|
}
|
|
869
959
|
session.cancelGrace();
|
|
870
|
-
log?.debug(`received msg`, {
|
|
960
|
+
this.log?.debug(`received msg`, {
|
|
871
961
|
clientId: this.clientId,
|
|
872
|
-
transportMessage: msg
|
|
962
|
+
transportMessage: msg,
|
|
963
|
+
...conn.loggingMetadata
|
|
873
964
|
});
|
|
874
965
|
if (msg.seq !== session.nextExpectedSeq) {
|
|
875
966
|
if (msg.seq < session.nextExpectedSeq) {
|
|
876
|
-
log?.debug(
|
|
967
|
+
this.log?.debug(
|
|
877
968
|
`received duplicate msg (got seq: ${msg.seq}, wanted seq: ${session.nextExpectedSeq}), discarding`,
|
|
878
|
-
{
|
|
969
|
+
{
|
|
970
|
+
clientId: this.clientId,
|
|
971
|
+
transportMessage: msg,
|
|
972
|
+
...conn.loggingMetadata
|
|
973
|
+
}
|
|
879
974
|
);
|
|
880
975
|
} else {
|
|
881
976
|
const errMsg = `received out-of-order msg (got seq: ${msg.seq}, wanted seq: ${session.nextExpectedSeq})`;
|
|
882
|
-
log?.error(`${errMsg}, marking connection as dead`, {
|
|
977
|
+
this.log?.error(`${errMsg}, marking connection as dead`, {
|
|
883
978
|
clientId: this.clientId,
|
|
884
979
|
transportMessage: msg,
|
|
980
|
+
...conn.loggingMetadata,
|
|
885
981
|
tags: ["invariant-violation"]
|
|
886
982
|
});
|
|
887
983
|
this.protocolError(ProtocolError.MessageOrderingViolated, errMsg);
|
|
@@ -897,9 +993,10 @@ var Transport = class {
|
|
|
897
993
|
if (!isAck(msg.controlFlags)) {
|
|
898
994
|
this.eventDispatcher.dispatchEvent("message", msg);
|
|
899
995
|
} else {
|
|
900
|
-
log?.debug(`discarding msg (ack bit set)`, {
|
|
996
|
+
this.log?.debug(`discarding msg (ack bit set)`, {
|
|
901
997
|
clientId: this.clientId,
|
|
902
|
-
transportMessage: msg
|
|
998
|
+
transportMessage: msg,
|
|
999
|
+
...conn.loggingMetadata
|
|
903
1000
|
});
|
|
904
1001
|
}
|
|
905
1002
|
}
|
|
@@ -928,7 +1025,7 @@ var Transport = class {
|
|
|
928
1025
|
send(to, msg) {
|
|
929
1026
|
if (this.state === "destroyed") {
|
|
930
1027
|
const err = "transport is destroyed, cant send";
|
|
931
|
-
log?.error(err, {
|
|
1028
|
+
this.log?.error(err, {
|
|
932
1029
|
clientId: this.clientId,
|
|
933
1030
|
transportMessage: msg,
|
|
934
1031
|
tags: ["invariant-violation"]
|
|
@@ -936,7 +1033,7 @@ var Transport = class {
|
|
|
936
1033
|
this.protocolError(ProtocolError.UseAfterDestroy, err);
|
|
937
1034
|
return void 0;
|
|
938
1035
|
} else if (this.state === "closed") {
|
|
939
|
-
log?.info(`transport closed when sending, discarding`, {
|
|
1036
|
+
this.log?.info(`transport closed when sending, discarding`, {
|
|
940
1037
|
clientId: this.clientId,
|
|
941
1038
|
transportMessage: msg
|
|
942
1039
|
});
|
|
@@ -967,7 +1064,7 @@ var Transport = class {
|
|
|
967
1064
|
for (const session of this.sessions.values()) {
|
|
968
1065
|
this.deleteSession(session);
|
|
969
1066
|
}
|
|
970
|
-
log?.info(`manually closed transport`, { clientId: this.clientId });
|
|
1067
|
+
this.log?.info(`manually closed transport`, { clientId: this.clientId });
|
|
971
1068
|
}
|
|
972
1069
|
/**
|
|
973
1070
|
* Default destroy implementation for transports. You should override this in the downstream
|
|
@@ -979,7 +1076,7 @@ var Transport = class {
|
|
|
979
1076
|
for (const session of this.sessions.values()) {
|
|
980
1077
|
this.deleteSession(session);
|
|
981
1078
|
}
|
|
982
|
-
log?.info(`manually destroyed transport`, { clientId: this.clientId });
|
|
1079
|
+
this.log?.info(`manually destroyed transport`, { clientId: this.clientId });
|
|
983
1080
|
}
|
|
984
1081
|
};
|
|
985
1082
|
var ClientTransport = class extends Transport {
|
|
@@ -1021,9 +1118,9 @@ var ClientTransport = class extends Transport {
|
|
|
1021
1118
|
let session = void 0;
|
|
1022
1119
|
const handshakeTimeout = setTimeout(() => {
|
|
1023
1120
|
if (!session) {
|
|
1024
|
-
log?.warn(
|
|
1121
|
+
this.log?.warn(
|
|
1025
1122
|
`connection to ${to} timed out waiting for handshake, closing`,
|
|
1026
|
-
{ clientId: this.clientId, connectedTo: to
|
|
1123
|
+
{ ...conn.loggingMetadata, clientId: this.clientId, connectedTo: to }
|
|
1027
1124
|
);
|
|
1028
1125
|
conn.close();
|
|
1029
1126
|
}
|
|
@@ -1039,7 +1136,7 @@ var ClientTransport = class extends Transport {
|
|
|
1039
1136
|
}
|
|
1040
1137
|
conn.removeDataListener(handshakeHandler);
|
|
1041
1138
|
conn.addDataListener((data2) => {
|
|
1042
|
-
const parsed = this.parseMsg(data2);
|
|
1139
|
+
const parsed = this.parseMsg(data2, conn);
|
|
1043
1140
|
if (!parsed) {
|
|
1044
1141
|
conn.telemetry?.span.setStatus({
|
|
1045
1142
|
code: import_api3.SpanStatusCode.ERROR,
|
|
@@ -1048,7 +1145,7 @@ var ClientTransport = class extends Transport {
|
|
|
1048
1145
|
conn.close();
|
|
1049
1146
|
return;
|
|
1050
1147
|
}
|
|
1051
|
-
this.handleMsg(parsed);
|
|
1148
|
+
this.handleMsg(parsed, conn);
|
|
1052
1149
|
});
|
|
1053
1150
|
};
|
|
1054
1151
|
conn.addDataListener(handshakeHandler);
|
|
@@ -1056,7 +1153,8 @@ var ClientTransport = class extends Transport {
|
|
|
1056
1153
|
if (session) {
|
|
1057
1154
|
this.onDisconnect(conn, session);
|
|
1058
1155
|
}
|
|
1059
|
-
log?.info(`connection to ${to} disconnected`, {
|
|
1156
|
+
this.log?.info(`connection to ${to} disconnected`, {
|
|
1157
|
+
...conn.loggingMetadata,
|
|
1060
1158
|
...session?.loggingMetadata,
|
|
1061
1159
|
clientId: this.clientId,
|
|
1062
1160
|
connectedTo: to
|
|
@@ -1071,15 +1169,19 @@ var ClientTransport = class extends Transport {
|
|
|
1071
1169
|
code: import_api3.SpanStatusCode.ERROR,
|
|
1072
1170
|
message: "connection error"
|
|
1073
1171
|
});
|
|
1074
|
-
log?.warn(
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1172
|
+
this.log?.warn(
|
|
1173
|
+
`error in connection to ${to}: ${coerceErrorString(err)}`,
|
|
1174
|
+
{
|
|
1175
|
+
...conn.loggingMetadata,
|
|
1176
|
+
...session?.loggingMetadata,
|
|
1177
|
+
clientId: this.clientId,
|
|
1178
|
+
connectedTo: to
|
|
1179
|
+
}
|
|
1180
|
+
);
|
|
1079
1181
|
});
|
|
1080
1182
|
}
|
|
1081
1183
|
receiveHandshakeResponseMessage(data, conn) {
|
|
1082
|
-
const parsed = this.parseMsg(data);
|
|
1184
|
+
const parsed = this.parseMsg(data, conn);
|
|
1083
1185
|
if (!parsed) {
|
|
1084
1186
|
conn.telemetry?.span.setStatus({
|
|
1085
1187
|
code: import_api3.SpanStatusCode.ERROR,
|
|
@@ -1096,7 +1198,8 @@ var ClientTransport = class extends Transport {
|
|
|
1096
1198
|
code: import_api3.SpanStatusCode.ERROR,
|
|
1097
1199
|
message: "invalid handshake response"
|
|
1098
1200
|
});
|
|
1099
|
-
log?.warn(`received invalid handshake resp`, {
|
|
1201
|
+
this.log?.warn(`received invalid handshake resp`, {
|
|
1202
|
+
...conn.loggingMetadata,
|
|
1100
1203
|
clientId: this.clientId,
|
|
1101
1204
|
connectedTo: parsed.from,
|
|
1102
1205
|
transportMessage: parsed,
|
|
@@ -1118,7 +1221,8 @@ var ClientTransport = class extends Transport {
|
|
|
1118
1221
|
code: import_api3.SpanStatusCode.ERROR,
|
|
1119
1222
|
message: "handshake rejected"
|
|
1120
1223
|
});
|
|
1121
|
-
log?.warn(`received handshake rejection`, {
|
|
1224
|
+
this.log?.warn(`received handshake rejection`, {
|
|
1225
|
+
...conn.loggingMetadata,
|
|
1122
1226
|
clientId: this.clientId,
|
|
1123
1227
|
connectedTo: parsed.from,
|
|
1124
1228
|
transportMessage: parsed
|
|
@@ -1129,7 +1233,8 @@ var ClientTransport = class extends Transport {
|
|
|
1129
1233
|
);
|
|
1130
1234
|
return false;
|
|
1131
1235
|
}
|
|
1132
|
-
log?.debug(`handshake from ${parsed.from} ok`, {
|
|
1236
|
+
this.log?.debug(`handshake from ${parsed.from} ok`, {
|
|
1237
|
+
...conn.loggingMetadata,
|
|
1133
1238
|
clientId: this.clientId,
|
|
1134
1239
|
connectedTo: parsed.from,
|
|
1135
1240
|
transportMessage: parsed
|
|
@@ -1150,7 +1255,7 @@ var ClientTransport = class extends Transport {
|
|
|
1150
1255
|
async connect(to) {
|
|
1151
1256
|
const canProceedWithConnection = () => this.state === "open";
|
|
1152
1257
|
if (!canProceedWithConnection()) {
|
|
1153
|
-
log?.info(
|
|
1258
|
+
this.log?.info(
|
|
1154
1259
|
`transport state is no longer open, cancelling attempt to connect to ${to}`,
|
|
1155
1260
|
{ clientId: this.clientId, connectedTo: to }
|
|
1156
1261
|
);
|
|
@@ -1161,7 +1266,7 @@ var ClientTransport = class extends Transport {
|
|
|
1161
1266
|
const budgetConsumed = this.retryBudget.getBudgetConsumed(to);
|
|
1162
1267
|
if (!this.retryBudget.hasBudget(to)) {
|
|
1163
1268
|
const errMsg = `tried to connect to ${to} but retry budget exceeded (more than ${budgetConsumed} attempts in the last ${this.retryBudget.totalBudgetRestoreTime}ms)`;
|
|
1164
|
-
log?.
|
|
1269
|
+
this.log?.error(errMsg, { clientId: this.clientId, connectedTo: to });
|
|
1165
1270
|
this.protocolError(ProtocolError.RetriesExceeded, errMsg);
|
|
1166
1271
|
return;
|
|
1167
1272
|
}
|
|
@@ -1170,10 +1275,13 @@ var ClientTransport = class extends Transport {
|
|
|
1170
1275
|
if (backoffMs > 0) {
|
|
1171
1276
|
sleep = new Promise((resolve) => setTimeout(resolve, backoffMs));
|
|
1172
1277
|
}
|
|
1173
|
-
log?.info(
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1278
|
+
this.log?.info(
|
|
1279
|
+
`attempting connection to ${to} (${backoffMs}ms backoff)`,
|
|
1280
|
+
{
|
|
1281
|
+
clientId: this.clientId,
|
|
1282
|
+
connectedTo: to
|
|
1283
|
+
}
|
|
1284
|
+
);
|
|
1177
1285
|
this.retryBudget.consumeBudget(to);
|
|
1178
1286
|
reconnectPromise = tracing_default.startActiveSpan("connect", async (span) => {
|
|
1179
1287
|
try {
|
|
@@ -1185,12 +1293,12 @@ var ClientTransport = class extends Transport {
|
|
|
1185
1293
|
span.addEvent("connecting");
|
|
1186
1294
|
const conn = await this.createNewOutgoingConnection(to);
|
|
1187
1295
|
if (!canProceedWithConnection()) {
|
|
1188
|
-
log?.info(
|
|
1296
|
+
this.log?.info(
|
|
1189
1297
|
`transport state is no longer open, closing pre-handshake connection to ${to}`,
|
|
1190
1298
|
{
|
|
1299
|
+
...conn.loggingMetadata,
|
|
1191
1300
|
clientId: this.clientId,
|
|
1192
|
-
connectedTo: to
|
|
1193
|
-
connId: conn.id
|
|
1301
|
+
connectedTo: to
|
|
1194
1302
|
}
|
|
1195
1303
|
);
|
|
1196
1304
|
conn.close();
|
|
@@ -1214,10 +1322,13 @@ var ClientTransport = class extends Transport {
|
|
|
1214
1322
|
});
|
|
1215
1323
|
this.inflightConnectionPromises.set(to, reconnectPromise);
|
|
1216
1324
|
} else {
|
|
1217
|
-
log?.info(
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1325
|
+
this.log?.info(
|
|
1326
|
+
`attempting connection to ${to} (reusing previous attempt)`,
|
|
1327
|
+
{
|
|
1328
|
+
clientId: this.clientId,
|
|
1329
|
+
connectedTo: to
|
|
1330
|
+
}
|
|
1331
|
+
);
|
|
1221
1332
|
}
|
|
1222
1333
|
try {
|
|
1223
1334
|
await reconnectPromise;
|
|
@@ -1225,12 +1336,12 @@ var ClientTransport = class extends Transport {
|
|
|
1225
1336
|
this.inflightConnectionPromises.delete(to);
|
|
1226
1337
|
const errStr = coerceErrorString(error);
|
|
1227
1338
|
if (!this.reconnectOnConnectionDrop || !canProceedWithConnection()) {
|
|
1228
|
-
log?.warn(`connection to ${to} failed (${errStr})`, {
|
|
1339
|
+
this.log?.warn(`connection to ${to} failed (${errStr})`, {
|
|
1229
1340
|
clientId: this.clientId,
|
|
1230
1341
|
connectedTo: to
|
|
1231
1342
|
});
|
|
1232
1343
|
} else {
|
|
1233
|
-
log?.warn(`connection to ${to} failed (${errStr}), retrying`, {
|
|
1344
|
+
this.log?.warn(`connection to ${to} failed (${errStr}), retrying`, {
|
|
1234
1345
|
clientId: this.clientId,
|
|
1235
1346
|
connectedTo: to
|
|
1236
1347
|
});
|
|
@@ -1247,7 +1358,8 @@ var ClientTransport = class extends Transport {
|
|
|
1247
1358
|
if (this.handshakeExtensions) {
|
|
1248
1359
|
metadata = await this.handshakeExtensions.construct();
|
|
1249
1360
|
if (!import_value.Value.Check(this.handshakeExtensions.schema, metadata)) {
|
|
1250
|
-
log?.error(`constructed handshake metadata did not match schema`, {
|
|
1361
|
+
this.log?.error(`constructed handshake metadata did not match schema`, {
|
|
1362
|
+
...conn.loggingMetadata,
|
|
1251
1363
|
clientId: this.clientId,
|
|
1252
1364
|
connectedTo: to,
|
|
1253
1365
|
validationErrors: [
|
|
@@ -1274,9 +1386,11 @@ var ClientTransport = class extends Transport {
|
|
|
1274
1386
|
metadata,
|
|
1275
1387
|
getPropagationContext(session.telemetry.ctx)
|
|
1276
1388
|
);
|
|
1277
|
-
log?.debug(`sending handshake request to ${to}`, {
|
|
1389
|
+
this.log?.debug(`sending handshake request to ${to}`, {
|
|
1390
|
+
...conn.loggingMetadata,
|
|
1278
1391
|
clientId: this.clientId,
|
|
1279
|
-
connectedTo: to
|
|
1392
|
+
connectedTo: to,
|
|
1393
|
+
transportMessage: requestMsg
|
|
1280
1394
|
});
|
|
1281
1395
|
conn.send(this.codec.toBuffer(requestMsg));
|
|
1282
1396
|
return true;
|
|
@@ -1299,7 +1413,7 @@ var UnixDomainSocketClientTransport = class extends ClientTransport {
|
|
|
1299
1413
|
if (oldConnection) {
|
|
1300
1414
|
oldConnection.close();
|
|
1301
1415
|
}
|
|
1302
|
-
log?.info(`establishing a new uds to ${to}`, {
|
|
1416
|
+
this.log?.info(`establishing a new uds to ${to}`, {
|
|
1303
1417
|
clientId: this.clientId,
|
|
1304
1418
|
connectedTo: to
|
|
1305
1419
|
});
|