@replit/river 0.23.6 → 0.23.8
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-GX2YS7BY.js → chunk-6LCL2ZZF.js} +17 -31
- package/dist/chunk-6LCL2ZZF.js.map +1 -0
- package/dist/{chunk-ZFN6I2GJ.js → chunk-CBNCT4B3.js} +2 -3
- package/dist/chunk-CBNCT4B3.js.map +1 -0
- package/dist/{chunk-NJJYBNYM.js → chunk-DXTG3E3B.js} +2 -2
- package/dist/{chunk-2PSMEETT.js → chunk-ELZRZNA5.js} +24 -11
- package/dist/{chunk-2PSMEETT.js.map → chunk-ELZRZNA5.js.map} +1 -1
- package/dist/{chunk-NB3OHLXB.js → chunk-RJ6CXPBM.js} +165 -101
- package/dist/chunk-RJ6CXPBM.js.map +1 -0
- package/dist/{chunk-7E53HHNS.js → chunk-WQRQFAP6.js} +33 -31
- package/dist/chunk-WQRQFAP6.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 -81
- 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 -74
- 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 +0 -1
- /package/dist/{chunk-NJJYBNYM.js.map → chunk-DXTG3E3B.js.map} +0 -0
|
@@ -106,7 +106,57 @@ function isAck(controlFlag) {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
// logging/log.ts
|
|
109
|
-
var
|
|
109
|
+
var LoggingLevels = {
|
|
110
|
+
debug: -1,
|
|
111
|
+
info: 0,
|
|
112
|
+
warn: 1,
|
|
113
|
+
error: 2
|
|
114
|
+
};
|
|
115
|
+
var cleanedLogFn = (log) => {
|
|
116
|
+
return (msg, metadata) => {
|
|
117
|
+
if (!metadata?.transportMessage) {
|
|
118
|
+
log(msg, metadata);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const { payload, ...rest } = metadata.transportMessage;
|
|
122
|
+
metadata.transportMessage = rest;
|
|
123
|
+
log(msg, metadata);
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
var BaseLogger = class {
|
|
127
|
+
minLevel;
|
|
128
|
+
output;
|
|
129
|
+
constructor(output, minLevel = "info") {
|
|
130
|
+
this.minLevel = minLevel;
|
|
131
|
+
this.output = output;
|
|
132
|
+
}
|
|
133
|
+
debug(msg, metadata) {
|
|
134
|
+
if (LoggingLevels[this.minLevel] <= LoggingLevels.debug) {
|
|
135
|
+
this.output(msg, metadata ?? {}, "debug");
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
info(msg, metadata) {
|
|
139
|
+
if (LoggingLevels[this.minLevel] <= LoggingLevels.info) {
|
|
140
|
+
this.output(msg, metadata ?? {}, "info");
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
warn(msg, metadata) {
|
|
144
|
+
if (LoggingLevels[this.minLevel] <= LoggingLevels.warn) {
|
|
145
|
+
this.output(msg, metadata ?? {}, "warn");
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
error(msg, metadata) {
|
|
149
|
+
if (LoggingLevels[this.minLevel] <= LoggingLevels.error) {
|
|
150
|
+
this.output(msg, metadata ?? {}, "error");
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
var createLogProxy = (log) => ({
|
|
155
|
+
debug: cleanedLogFn(log.debug.bind(log)),
|
|
156
|
+
info: cleanedLogFn(log.info.bind(log)),
|
|
157
|
+
warn: cleanedLogFn(log.warn.bind(log)),
|
|
158
|
+
error: cleanedLogFn(log.error.bind(log))
|
|
159
|
+
});
|
|
110
160
|
|
|
111
161
|
// transport/events.ts
|
|
112
162
|
var ProtocolError = {
|
|
@@ -149,7 +199,7 @@ var import_nanoid2 = require("nanoid");
|
|
|
149
199
|
var import_api = require("@opentelemetry/api");
|
|
150
200
|
|
|
151
201
|
// package.json
|
|
152
|
-
var version = "0.23.
|
|
202
|
+
var version = "0.23.8";
|
|
153
203
|
|
|
154
204
|
// tracing/index.ts
|
|
155
205
|
function getPropagationContext(ctx) {
|
|
@@ -161,7 +211,7 @@ function getPropagationContext(ctx) {
|
|
|
161
211
|
return tracing;
|
|
162
212
|
}
|
|
163
213
|
function createSessionTelemetryInfo(session, propagationCtx) {
|
|
164
|
-
const
|
|
214
|
+
const parentCtx = propagationCtx ? import_api.propagation.extract(import_api.context.active(), propagationCtx) : import_api.context.active();
|
|
165
215
|
const span = tracer.startSpan(
|
|
166
216
|
`session ${session.id}`,
|
|
167
217
|
{
|
|
@@ -172,12 +222,12 @@ function createSessionTelemetryInfo(session, propagationCtx) {
|
|
|
172
222
|
"river.session.from": session.from
|
|
173
223
|
}
|
|
174
224
|
},
|
|
175
|
-
|
|
225
|
+
parentCtx
|
|
176
226
|
);
|
|
227
|
+
const ctx = import_api.trace.setSpan(parentCtx, span);
|
|
177
228
|
return { span, ctx };
|
|
178
229
|
}
|
|
179
|
-
function createConnectionTelemetryInfo(connection,
|
|
180
|
-
const ctx = import_api.trace.setSpan(import_api.context.active(), sessionSpan);
|
|
230
|
+
function createConnectionTelemetryInfo(connection, info) {
|
|
181
231
|
const span = tracer.startSpan(
|
|
182
232
|
`connection ${connection.id}`,
|
|
183
233
|
{
|
|
@@ -185,10 +235,11 @@ function createConnectionTelemetryInfo(connection, sessionSpan) {
|
|
|
185
235
|
component: "river",
|
|
186
236
|
"river.connection.id": connection.id
|
|
187
237
|
},
|
|
188
|
-
links: [{ context:
|
|
238
|
+
links: [{ context: info.span.spanContext() }]
|
|
189
239
|
},
|
|
190
|
-
ctx
|
|
240
|
+
info.ctx
|
|
191
241
|
);
|
|
242
|
+
const ctx = import_api.trace.setSpan(info.ctx, span);
|
|
192
243
|
return { span, ctx };
|
|
193
244
|
}
|
|
194
245
|
var tracer = import_api.trace.getTracer("river", version);
|
|
@@ -204,6 +255,17 @@ var Connection = class {
|
|
|
204
255
|
constructor() {
|
|
205
256
|
this.id = `conn-${nanoid2(12)}`;
|
|
206
257
|
}
|
|
258
|
+
get loggingMetadata() {
|
|
259
|
+
const metadata = { connId: this.id };
|
|
260
|
+
const spanContext = this.telemetry?.span.spanContext();
|
|
261
|
+
if (spanContext) {
|
|
262
|
+
metadata.telemetry = {
|
|
263
|
+
traceId: spanContext.traceId,
|
|
264
|
+
spanId: spanContext.spanId
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
return metadata;
|
|
268
|
+
}
|
|
207
269
|
};
|
|
208
270
|
var Session = class {
|
|
209
271
|
codec;
|
|
@@ -249,6 +311,7 @@ var Session = class {
|
|
|
249
311
|
* The interval for sending heartbeats.
|
|
250
312
|
*/
|
|
251
313
|
heartbeat;
|
|
314
|
+
log;
|
|
252
315
|
constructor(conn, from, to, options, propagationCtx) {
|
|
253
316
|
this.id = `session-${nanoid2(12)}`;
|
|
254
317
|
this.options = options;
|
|
@@ -263,12 +326,20 @@ var Session = class {
|
|
|
263
326
|
);
|
|
264
327
|
this.telemetry = createSessionTelemetryInfo(this, propagationCtx);
|
|
265
328
|
}
|
|
329
|
+
bindLogger(log) {
|
|
330
|
+
this.log = log;
|
|
331
|
+
}
|
|
266
332
|
get loggingMetadata() {
|
|
333
|
+
const spanContext = this.telemetry.span.spanContext();
|
|
267
334
|
return {
|
|
268
335
|
clientId: this.from,
|
|
269
336
|
connectedTo: this.to,
|
|
270
337
|
sessionId: this.id,
|
|
271
|
-
connId: this.connection?.id
|
|
338
|
+
connId: this.connection?.id,
|
|
339
|
+
telemetry: {
|
|
340
|
+
traceId: spanContext.traceId,
|
|
341
|
+
spanId: spanContext.spanId
|
|
342
|
+
}
|
|
272
343
|
};
|
|
273
344
|
}
|
|
274
345
|
/**
|
|
@@ -281,7 +352,7 @@ var Session = class {
|
|
|
281
352
|
*/
|
|
282
353
|
send(msg) {
|
|
283
354
|
const fullMsg = this.constructMsg(msg);
|
|
284
|
-
log?.debug(`sending msg`, {
|
|
355
|
+
this.log?.debug(`sending msg`, {
|
|
285
356
|
...this.loggingMetadata,
|
|
286
357
|
transportMessage: fullMsg
|
|
287
358
|
});
|
|
@@ -289,7 +360,7 @@ var Session = class {
|
|
|
289
360
|
const ok = this.connection.send(this.codec.toBuffer(fullMsg));
|
|
290
361
|
if (ok)
|
|
291
362
|
return fullMsg.id;
|
|
292
|
-
log?.info(
|
|
363
|
+
this.log?.info(
|
|
293
364
|
`failed to send msg to ${fullMsg.to}, connection is probably dead`,
|
|
294
365
|
{
|
|
295
366
|
...this.loggingMetadata,
|
|
@@ -297,8 +368,8 @@ var Session = class {
|
|
|
297
368
|
}
|
|
298
369
|
);
|
|
299
370
|
} else {
|
|
300
|
-
log?.
|
|
301
|
-
`
|
|
371
|
+
this.log?.debug(
|
|
372
|
+
`buffering msg to ${fullMsg.to}, connection not ready yet`,
|
|
302
373
|
{ ...this.loggingMetadata, transportMessage: fullMsg }
|
|
303
374
|
);
|
|
304
375
|
}
|
|
@@ -309,7 +380,7 @@ var Session = class {
|
|
|
309
380
|
const missDuration = misses * this.options.heartbeatIntervalMs;
|
|
310
381
|
if (misses > this.options.heartbeatsUntilDead) {
|
|
311
382
|
if (this.connection) {
|
|
312
|
-
log?.info(
|
|
383
|
+
this.log?.info(
|
|
313
384
|
`closing connection to ${this.to} due to inactivity (missed ${misses} heartbeats which is ${missDuration}ms)`,
|
|
314
385
|
this.loggingMetadata
|
|
315
386
|
);
|
|
@@ -333,12 +404,12 @@ var Session = class {
|
|
|
333
404
|
this.ack = 0;
|
|
334
405
|
}
|
|
335
406
|
sendBufferedMessages(conn) {
|
|
336
|
-
log?.info(`resending ${this.sendBuffer.length} buffered messages`, {
|
|
407
|
+
this.log?.info(`resending ${this.sendBuffer.length} buffered messages`, {
|
|
337
408
|
...this.loggingMetadata,
|
|
338
409
|
connId: conn.id
|
|
339
410
|
});
|
|
340
411
|
for (const msg of this.sendBuffer) {
|
|
341
|
-
log?.debug(`resending msg`, {
|
|
412
|
+
this.log?.debug(`resending msg`, {
|
|
342
413
|
...this.loggingMetadata,
|
|
343
414
|
transportMessage: msg,
|
|
344
415
|
connId: conn.id
|
|
@@ -350,7 +421,7 @@ var Session = class {
|
|
|
350
421
|
code: import_api2.SpanStatusCode.ERROR,
|
|
351
422
|
message: errMsg
|
|
352
423
|
});
|
|
353
|
-
log?.error(errMsg, {
|
|
424
|
+
this.log?.error(errMsg, {
|
|
354
425
|
...this.loggingMetadata,
|
|
355
426
|
transportMessage: msg,
|
|
356
427
|
connId: conn.id,
|
|
@@ -363,7 +434,7 @@ var Session = class {
|
|
|
363
434
|
}
|
|
364
435
|
updateBookkeeping(ack, seq) {
|
|
365
436
|
if (seq + 1 < this.ack) {
|
|
366
|
-
log?.error(`received stale seq ${seq} + 1 < ${this.ack}`, {
|
|
437
|
+
this.log?.error(`received stale seq ${seq} + 1 < ${this.ack}`, {
|
|
367
438
|
...this.loggingMetadata,
|
|
368
439
|
tags: ["invariant-violation"]
|
|
369
440
|
});
|
|
@@ -375,7 +446,7 @@ var Session = class {
|
|
|
375
446
|
closeStaleConnection(conn) {
|
|
376
447
|
if (this.connection === void 0 || this.connection === conn)
|
|
377
448
|
return;
|
|
378
|
-
log?.info(
|
|
449
|
+
this.log?.info(
|
|
379
450
|
`closing old inner connection from session to ${this.to}`,
|
|
380
451
|
this.loggingMetadata
|
|
381
452
|
);
|
|
@@ -389,7 +460,7 @@ var Session = class {
|
|
|
389
460
|
this.connection = newConn;
|
|
390
461
|
}
|
|
391
462
|
beginGrace(cb) {
|
|
392
|
-
log?.info(
|
|
463
|
+
this.log?.info(
|
|
393
464
|
`starting ${this.options.sessionDisconnectGraceMs}ms grace period until session to ${this.to} is closed`,
|
|
394
465
|
this.loggingMetadata
|
|
395
466
|
);
|
|
@@ -623,6 +694,7 @@ var Transport = class {
|
|
|
623
694
|
* The options for this transport.
|
|
624
695
|
*/
|
|
625
696
|
options;
|
|
697
|
+
log;
|
|
626
698
|
/**
|
|
627
699
|
* Creates a new Transport instance.
|
|
628
700
|
* This should also set up {@link onConnect}, and {@link onDisconnect} listeners.
|
|
@@ -637,6 +709,13 @@ var Transport = class {
|
|
|
637
709
|
this.clientId = clientId;
|
|
638
710
|
this.state = "open";
|
|
639
711
|
}
|
|
712
|
+
bindLogger(fn, level) {
|
|
713
|
+
if (typeof fn === "function") {
|
|
714
|
+
this.log = createLogProxy(new BaseLogger(fn, level));
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
this.log = createLogProxy(fn);
|
|
718
|
+
}
|
|
640
719
|
/**
|
|
641
720
|
* Called when a new connection is established
|
|
642
721
|
* and we know the identity of the connected client.
|
|
@@ -647,13 +726,15 @@ var Transport = class {
|
|
|
647
726
|
status: "connect",
|
|
648
727
|
conn
|
|
649
728
|
});
|
|
650
|
-
conn.telemetry = createConnectionTelemetryInfo(
|
|
651
|
-
conn,
|
|
652
|
-
session.telemetry.span
|
|
653
|
-
);
|
|
729
|
+
conn.telemetry = createConnectionTelemetryInfo(conn, session.telemetry);
|
|
654
730
|
if (isReconnect) {
|
|
655
731
|
session.replaceWithNewConnection(conn);
|
|
656
|
-
log?.info(`reconnected to ${connectedTo}`,
|
|
732
|
+
this.log?.info(`reconnected to ${connectedTo}`, {
|
|
733
|
+
...conn.loggingMetadata,
|
|
734
|
+
...session.loggingMetadata,
|
|
735
|
+
clientId: this.clientId,
|
|
736
|
+
connectedTo
|
|
737
|
+
});
|
|
657
738
|
}
|
|
658
739
|
}
|
|
659
740
|
createSession(to, conn, propagationCtx) {
|
|
@@ -664,6 +745,9 @@ var Transport = class {
|
|
|
664
745
|
this.options,
|
|
665
746
|
propagationCtx
|
|
666
747
|
);
|
|
748
|
+
if (this.log) {
|
|
749
|
+
session.bindLogger(this.log);
|
|
750
|
+
}
|
|
667
751
|
this.sessions.set(session.to, session);
|
|
668
752
|
this.eventDispatcher.dispatchEvent("sessionStatus", {
|
|
669
753
|
status: "connect",
|
|
@@ -675,7 +759,7 @@ var Transport = class {
|
|
|
675
759
|
let session = this.sessions.get(to);
|
|
676
760
|
let isReconnect = session !== void 0;
|
|
677
761
|
if (session?.advertisedSessionId !== void 0 && sessionId !== void 0 && session.advertisedSessionId !== sessionId) {
|
|
678
|
-
log?.info(
|
|
762
|
+
this.log?.info(
|
|
679
763
|
`session for ${to} already exists but has a different session id (expected: ${session.advertisedSessionId}, got: ${sessionId}), creating a new one`,
|
|
680
764
|
session.loggingMetadata
|
|
681
765
|
);
|
|
@@ -685,7 +769,7 @@ var Transport = class {
|
|
|
685
769
|
}
|
|
686
770
|
if (!session) {
|
|
687
771
|
session = this.createSession(to, conn, propagationCtx);
|
|
688
|
-
log?.info(
|
|
772
|
+
this.log?.info(
|
|
689
773
|
`no session for ${to}, created a new one`,
|
|
690
774
|
session.loggingMetadata
|
|
691
775
|
);
|
|
@@ -699,7 +783,7 @@ var Transport = class {
|
|
|
699
783
|
session.close();
|
|
700
784
|
session.telemetry.span.end();
|
|
701
785
|
this.sessions.delete(session.to);
|
|
702
|
-
log?.info(
|
|
786
|
+
this.log?.info(
|
|
703
787
|
`session ${session.id} disconnect from ${session.to}`,
|
|
704
788
|
session.loggingMetadata
|
|
705
789
|
);
|
|
@@ -730,18 +814,23 @@ var Transport = class {
|
|
|
730
814
|
* @param msg The message to parse.
|
|
731
815
|
* @returns The parsed message, or null if the message is malformed or invalid.
|
|
732
816
|
*/
|
|
733
|
-
parseMsg(msg) {
|
|
817
|
+
parseMsg(msg, conn) {
|
|
734
818
|
const parsedMsg = this.codec.fromBuffer(msg);
|
|
735
819
|
if (parsedMsg === null) {
|
|
736
820
|
const decodedBuffer = new TextDecoder().decode(Buffer.from(msg));
|
|
737
|
-
log?.error(
|
|
738
|
-
|
|
739
|
-
|
|
821
|
+
this.log?.error(
|
|
822
|
+
`received malformed msg, killing conn: ${decodedBuffer}`,
|
|
823
|
+
{
|
|
824
|
+
clientId: this.clientId,
|
|
825
|
+
...conn.loggingMetadata
|
|
826
|
+
}
|
|
827
|
+
);
|
|
740
828
|
return null;
|
|
741
829
|
}
|
|
742
830
|
if (!import_value.Value.Check(OpaqueTransportMessageSchema, parsedMsg)) {
|
|
743
|
-
log?.error(`received invalid msg: ${JSON.stringify(parsedMsg)}`, {
|
|
831
|
+
this.log?.error(`received invalid msg: ${JSON.stringify(parsedMsg)}`, {
|
|
744
832
|
clientId: this.clientId,
|
|
833
|
+
...conn.loggingMetadata,
|
|
745
834
|
validationErrors: [
|
|
746
835
|
...import_value.Value.Errors(OpaqueTransportMessageSchema, parsedMsg)
|
|
747
836
|
]
|
|
@@ -755,34 +844,41 @@ var Transport = class {
|
|
|
755
844
|
* You generally shouldn't need to override this in downstream transport implementations.
|
|
756
845
|
* @param msg The received message.
|
|
757
846
|
*/
|
|
758
|
-
handleMsg(msg) {
|
|
847
|
+
handleMsg(msg, conn) {
|
|
759
848
|
if (this.state !== "open")
|
|
760
849
|
return;
|
|
761
850
|
const session = this.sessions.get(msg.from);
|
|
762
851
|
if (!session) {
|
|
763
|
-
log?.error(`
|
|
852
|
+
this.log?.error(`received message for unknown session from ${msg.from}`, {
|
|
764
853
|
clientId: this.clientId,
|
|
765
854
|
transportMessage: msg,
|
|
855
|
+
...conn.loggingMetadata,
|
|
766
856
|
tags: ["invariant-violation"]
|
|
767
857
|
});
|
|
768
858
|
return;
|
|
769
859
|
}
|
|
770
860
|
session.cancelGrace();
|
|
771
|
-
log?.debug(`received msg`, {
|
|
861
|
+
this.log?.debug(`received msg`, {
|
|
772
862
|
clientId: this.clientId,
|
|
773
|
-
transportMessage: msg
|
|
863
|
+
transportMessage: msg,
|
|
864
|
+
...conn.loggingMetadata
|
|
774
865
|
});
|
|
775
866
|
if (msg.seq !== session.nextExpectedSeq) {
|
|
776
867
|
if (msg.seq < session.nextExpectedSeq) {
|
|
777
|
-
log?.debug(
|
|
868
|
+
this.log?.debug(
|
|
778
869
|
`received duplicate msg (got seq: ${msg.seq}, wanted seq: ${session.nextExpectedSeq}), discarding`,
|
|
779
|
-
{
|
|
870
|
+
{
|
|
871
|
+
clientId: this.clientId,
|
|
872
|
+
transportMessage: msg,
|
|
873
|
+
...conn.loggingMetadata
|
|
874
|
+
}
|
|
780
875
|
);
|
|
781
876
|
} else {
|
|
782
877
|
const errMsg = `received out-of-order msg (got seq: ${msg.seq}, wanted seq: ${session.nextExpectedSeq})`;
|
|
783
|
-
log?.error(`${errMsg}, marking connection as dead`, {
|
|
878
|
+
this.log?.error(`${errMsg}, marking connection as dead`, {
|
|
784
879
|
clientId: this.clientId,
|
|
785
880
|
transportMessage: msg,
|
|
881
|
+
...conn.loggingMetadata,
|
|
786
882
|
tags: ["invariant-violation"]
|
|
787
883
|
});
|
|
788
884
|
this.protocolError(ProtocolError.MessageOrderingViolated, errMsg);
|
|
@@ -798,9 +894,10 @@ var Transport = class {
|
|
|
798
894
|
if (!isAck(msg.controlFlags)) {
|
|
799
895
|
this.eventDispatcher.dispatchEvent("message", msg);
|
|
800
896
|
} else {
|
|
801
|
-
log?.debug(`discarding msg (ack bit set)`, {
|
|
897
|
+
this.log?.debug(`discarding msg (ack bit set)`, {
|
|
802
898
|
clientId: this.clientId,
|
|
803
|
-
transportMessage: msg
|
|
899
|
+
transportMessage: msg,
|
|
900
|
+
...conn.loggingMetadata
|
|
804
901
|
});
|
|
805
902
|
}
|
|
806
903
|
}
|
|
@@ -829,7 +926,7 @@ var Transport = class {
|
|
|
829
926
|
send(to, msg) {
|
|
830
927
|
if (this.state === "destroyed") {
|
|
831
928
|
const err = "transport is destroyed, cant send";
|
|
832
|
-
log?.error(err, {
|
|
929
|
+
this.log?.error(err, {
|
|
833
930
|
clientId: this.clientId,
|
|
834
931
|
transportMessage: msg,
|
|
835
932
|
tags: ["invariant-violation"]
|
|
@@ -837,7 +934,7 @@ var Transport = class {
|
|
|
837
934
|
this.protocolError(ProtocolError.UseAfterDestroy, err);
|
|
838
935
|
return void 0;
|
|
839
936
|
} else if (this.state === "closed") {
|
|
840
|
-
log?.info(`transport closed when sending, discarding`, {
|
|
937
|
+
this.log?.info(`transport closed when sending, discarding`, {
|
|
841
938
|
clientId: this.clientId,
|
|
842
939
|
transportMessage: msg
|
|
843
940
|
});
|
|
@@ -868,7 +965,7 @@ var Transport = class {
|
|
|
868
965
|
for (const session of this.sessions.values()) {
|
|
869
966
|
this.deleteSession(session);
|
|
870
967
|
}
|
|
871
|
-
log?.info(`manually closed transport`, { clientId: this.clientId });
|
|
968
|
+
this.log?.info(`manually closed transport`, { clientId: this.clientId });
|
|
872
969
|
}
|
|
873
970
|
/**
|
|
874
971
|
* Default destroy implementation for transports. You should override this in the downstream
|
|
@@ -880,7 +977,7 @@ var Transport = class {
|
|
|
880
977
|
for (const session of this.sessions.values()) {
|
|
881
978
|
this.deleteSession(session);
|
|
882
979
|
}
|
|
883
|
-
log?.info(`manually destroyed transport`, { clientId: this.clientId });
|
|
980
|
+
this.log?.info(`manually destroyed transport`, { clientId: this.clientId });
|
|
884
981
|
}
|
|
885
982
|
};
|
|
886
983
|
var ClientTransport = class extends Transport {
|
|
@@ -922,9 +1019,9 @@ var ClientTransport = class extends Transport {
|
|
|
922
1019
|
let session = void 0;
|
|
923
1020
|
const handshakeTimeout = setTimeout(() => {
|
|
924
1021
|
if (!session) {
|
|
925
|
-
log?.warn(
|
|
1022
|
+
this.log?.warn(
|
|
926
1023
|
`connection to ${to} timed out waiting for handshake, closing`,
|
|
927
|
-
{ clientId: this.clientId, connectedTo: to
|
|
1024
|
+
{ ...conn.loggingMetadata, clientId: this.clientId, connectedTo: to }
|
|
928
1025
|
);
|
|
929
1026
|
conn.close();
|
|
930
1027
|
}
|
|
@@ -940,7 +1037,7 @@ var ClientTransport = class extends Transport {
|
|
|
940
1037
|
}
|
|
941
1038
|
conn.removeDataListener(handshakeHandler);
|
|
942
1039
|
conn.addDataListener((data2) => {
|
|
943
|
-
const parsed = this.parseMsg(data2);
|
|
1040
|
+
const parsed = this.parseMsg(data2, conn);
|
|
944
1041
|
if (!parsed) {
|
|
945
1042
|
conn.telemetry?.span.setStatus({
|
|
946
1043
|
code: import_api3.SpanStatusCode.ERROR,
|
|
@@ -949,7 +1046,7 @@ var ClientTransport = class extends Transport {
|
|
|
949
1046
|
conn.close();
|
|
950
1047
|
return;
|
|
951
1048
|
}
|
|
952
|
-
this.handleMsg(parsed);
|
|
1049
|
+
this.handleMsg(parsed, conn);
|
|
953
1050
|
});
|
|
954
1051
|
};
|
|
955
1052
|
conn.addDataListener(handshakeHandler);
|
|
@@ -957,7 +1054,8 @@ var ClientTransport = class extends Transport {
|
|
|
957
1054
|
if (session) {
|
|
958
1055
|
this.onDisconnect(conn, session);
|
|
959
1056
|
}
|
|
960
|
-
log?.info(`connection to ${to} disconnected`, {
|
|
1057
|
+
this.log?.info(`connection to ${to} disconnected`, {
|
|
1058
|
+
...conn.loggingMetadata,
|
|
961
1059
|
...session?.loggingMetadata,
|
|
962
1060
|
clientId: this.clientId,
|
|
963
1061
|
connectedTo: to
|
|
@@ -972,15 +1070,19 @@ var ClientTransport = class extends Transport {
|
|
|
972
1070
|
code: import_api3.SpanStatusCode.ERROR,
|
|
973
1071
|
message: "connection error"
|
|
974
1072
|
});
|
|
975
|
-
log?.warn(
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
1073
|
+
this.log?.warn(
|
|
1074
|
+
`error in connection to ${to}: ${coerceErrorString(err)}`,
|
|
1075
|
+
{
|
|
1076
|
+
...conn.loggingMetadata,
|
|
1077
|
+
...session?.loggingMetadata,
|
|
1078
|
+
clientId: this.clientId,
|
|
1079
|
+
connectedTo: to
|
|
1080
|
+
}
|
|
1081
|
+
);
|
|
980
1082
|
});
|
|
981
1083
|
}
|
|
982
1084
|
receiveHandshakeResponseMessage(data, conn) {
|
|
983
|
-
const parsed = this.parseMsg(data);
|
|
1085
|
+
const parsed = this.parseMsg(data, conn);
|
|
984
1086
|
if (!parsed) {
|
|
985
1087
|
conn.telemetry?.span.setStatus({
|
|
986
1088
|
code: import_api3.SpanStatusCode.ERROR,
|
|
@@ -997,7 +1099,8 @@ var ClientTransport = class extends Transport {
|
|
|
997
1099
|
code: import_api3.SpanStatusCode.ERROR,
|
|
998
1100
|
message: "invalid handshake response"
|
|
999
1101
|
});
|
|
1000
|
-
log?.warn(`received invalid handshake resp`, {
|
|
1102
|
+
this.log?.warn(`received invalid handshake resp`, {
|
|
1103
|
+
...conn.loggingMetadata,
|
|
1001
1104
|
clientId: this.clientId,
|
|
1002
1105
|
connectedTo: parsed.from,
|
|
1003
1106
|
transportMessage: parsed,
|
|
@@ -1019,7 +1122,8 @@ var ClientTransport = class extends Transport {
|
|
|
1019
1122
|
code: import_api3.SpanStatusCode.ERROR,
|
|
1020
1123
|
message: "handshake rejected"
|
|
1021
1124
|
});
|
|
1022
|
-
log?.warn(`received handshake rejection`, {
|
|
1125
|
+
this.log?.warn(`received handshake rejection`, {
|
|
1126
|
+
...conn.loggingMetadata,
|
|
1023
1127
|
clientId: this.clientId,
|
|
1024
1128
|
connectedTo: parsed.from,
|
|
1025
1129
|
transportMessage: parsed
|
|
@@ -1030,7 +1134,8 @@ var ClientTransport = class extends Transport {
|
|
|
1030
1134
|
);
|
|
1031
1135
|
return false;
|
|
1032
1136
|
}
|
|
1033
|
-
log?.debug(`handshake from ${parsed.from} ok`, {
|
|
1137
|
+
this.log?.debug(`handshake from ${parsed.from} ok`, {
|
|
1138
|
+
...conn.loggingMetadata,
|
|
1034
1139
|
clientId: this.clientId,
|
|
1035
1140
|
connectedTo: parsed.from,
|
|
1036
1141
|
transportMessage: parsed
|
|
@@ -1051,7 +1156,7 @@ var ClientTransport = class extends Transport {
|
|
|
1051
1156
|
async connect(to) {
|
|
1052
1157
|
const canProceedWithConnection = () => this.state === "open";
|
|
1053
1158
|
if (!canProceedWithConnection()) {
|
|
1054
|
-
log?.info(
|
|
1159
|
+
this.log?.info(
|
|
1055
1160
|
`transport state is no longer open, cancelling attempt to connect to ${to}`,
|
|
1056
1161
|
{ clientId: this.clientId, connectedTo: to }
|
|
1057
1162
|
);
|
|
@@ -1062,7 +1167,7 @@ var ClientTransport = class extends Transport {
|
|
|
1062
1167
|
const budgetConsumed = this.retryBudget.getBudgetConsumed(to);
|
|
1063
1168
|
if (!this.retryBudget.hasBudget(to)) {
|
|
1064
1169
|
const errMsg = `tried to connect to ${to} but retry budget exceeded (more than ${budgetConsumed} attempts in the last ${this.retryBudget.totalBudgetRestoreTime}ms)`;
|
|
1065
|
-
log?.
|
|
1170
|
+
this.log?.error(errMsg, { clientId: this.clientId, connectedTo: to });
|
|
1066
1171
|
this.protocolError(ProtocolError.RetriesExceeded, errMsg);
|
|
1067
1172
|
return;
|
|
1068
1173
|
}
|
|
@@ -1071,10 +1176,13 @@ var ClientTransport = class extends Transport {
|
|
|
1071
1176
|
if (backoffMs > 0) {
|
|
1072
1177
|
sleep = new Promise((resolve) => setTimeout(resolve, backoffMs));
|
|
1073
1178
|
}
|
|
1074
|
-
log?.info(
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1179
|
+
this.log?.info(
|
|
1180
|
+
`attempting connection to ${to} (${backoffMs}ms backoff)`,
|
|
1181
|
+
{
|
|
1182
|
+
clientId: this.clientId,
|
|
1183
|
+
connectedTo: to
|
|
1184
|
+
}
|
|
1185
|
+
);
|
|
1078
1186
|
this.retryBudget.consumeBudget(to);
|
|
1079
1187
|
reconnectPromise = tracing_default.startActiveSpan("connect", async (span) => {
|
|
1080
1188
|
try {
|
|
@@ -1086,12 +1194,12 @@ var ClientTransport = class extends Transport {
|
|
|
1086
1194
|
span.addEvent("connecting");
|
|
1087
1195
|
const conn = await this.createNewOutgoingConnection(to);
|
|
1088
1196
|
if (!canProceedWithConnection()) {
|
|
1089
|
-
log?.info(
|
|
1197
|
+
this.log?.info(
|
|
1090
1198
|
`transport state is no longer open, closing pre-handshake connection to ${to}`,
|
|
1091
1199
|
{
|
|
1200
|
+
...conn.loggingMetadata,
|
|
1092
1201
|
clientId: this.clientId,
|
|
1093
|
-
connectedTo: to
|
|
1094
|
-
connId: conn.id
|
|
1202
|
+
connectedTo: to
|
|
1095
1203
|
}
|
|
1096
1204
|
);
|
|
1097
1205
|
conn.close();
|
|
@@ -1115,10 +1223,13 @@ var ClientTransport = class extends Transport {
|
|
|
1115
1223
|
});
|
|
1116
1224
|
this.inflightConnectionPromises.set(to, reconnectPromise);
|
|
1117
1225
|
} else {
|
|
1118
|
-
log?.info(
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1226
|
+
this.log?.info(
|
|
1227
|
+
`attempting connection to ${to} (reusing previous attempt)`,
|
|
1228
|
+
{
|
|
1229
|
+
clientId: this.clientId,
|
|
1230
|
+
connectedTo: to
|
|
1231
|
+
}
|
|
1232
|
+
);
|
|
1122
1233
|
}
|
|
1123
1234
|
try {
|
|
1124
1235
|
await reconnectPromise;
|
|
@@ -1126,12 +1237,12 @@ var ClientTransport = class extends Transport {
|
|
|
1126
1237
|
this.inflightConnectionPromises.delete(to);
|
|
1127
1238
|
const errStr = coerceErrorString(error);
|
|
1128
1239
|
if (!this.reconnectOnConnectionDrop || !canProceedWithConnection()) {
|
|
1129
|
-
log?.warn(`connection to ${to} failed (${errStr})`, {
|
|
1240
|
+
this.log?.warn(`connection to ${to} failed (${errStr})`, {
|
|
1130
1241
|
clientId: this.clientId,
|
|
1131
1242
|
connectedTo: to
|
|
1132
1243
|
});
|
|
1133
1244
|
} else {
|
|
1134
|
-
log?.warn(`connection to ${to} failed (${errStr}), retrying`, {
|
|
1245
|
+
this.log?.warn(`connection to ${to} failed (${errStr}), retrying`, {
|
|
1135
1246
|
clientId: this.clientId,
|
|
1136
1247
|
connectedTo: to
|
|
1137
1248
|
});
|
|
@@ -1148,7 +1259,8 @@ var ClientTransport = class extends Transport {
|
|
|
1148
1259
|
if (this.handshakeExtensions) {
|
|
1149
1260
|
metadata = await this.handshakeExtensions.construct();
|
|
1150
1261
|
if (!import_value.Value.Check(this.handshakeExtensions.schema, metadata)) {
|
|
1151
|
-
log?.error(`constructed handshake metadata did not match schema`, {
|
|
1262
|
+
this.log?.error(`constructed handshake metadata did not match schema`, {
|
|
1263
|
+
...conn.loggingMetadata,
|
|
1152
1264
|
clientId: this.clientId,
|
|
1153
1265
|
connectedTo: to,
|
|
1154
1266
|
validationErrors: [
|
|
@@ -1175,9 +1287,11 @@ var ClientTransport = class extends Transport {
|
|
|
1175
1287
|
metadata,
|
|
1176
1288
|
getPropagationContext(session.telemetry.ctx)
|
|
1177
1289
|
);
|
|
1178
|
-
log?.debug(`sending handshake request to ${to}`, {
|
|
1290
|
+
this.log?.debug(`sending handshake request to ${to}`, {
|
|
1291
|
+
...conn.loggingMetadata,
|
|
1179
1292
|
clientId: this.clientId,
|
|
1180
|
-
connectedTo: to
|
|
1293
|
+
connectedTo: to,
|
|
1294
|
+
transportMessage: requestMsg
|
|
1181
1295
|
});
|
|
1182
1296
|
conn.send(this.codec.toBuffer(requestMsg));
|
|
1183
1297
|
return true;
|
|
@@ -1208,7 +1322,6 @@ var WebSocketConnection = class extends Connection {
|
|
|
1208
1322
|
`websocket closed with code and reason: ${code} - ${reason}`
|
|
1209
1323
|
)
|
|
1210
1324
|
);
|
|
1211
|
-
return;
|
|
1212
1325
|
}
|
|
1213
1326
|
if (this.closeCb) {
|
|
1214
1327
|
this.closeCb();
|
|
@@ -1258,7 +1371,7 @@ var WebSocketClientTransport = class extends ClientTransport {
|
|
|
1258
1371
|
this.wsGetter = wsGetter;
|
|
1259
1372
|
}
|
|
1260
1373
|
async createNewOutgoingConnection(to) {
|
|
1261
|
-
log?.info(`establishing a new websocket to ${to}`, {
|
|
1374
|
+
this.log?.info(`establishing a new websocket to ${to}`, {
|
|
1262
1375
|
clientId: this.clientId,
|
|
1263
1376
|
connectedTo: to
|
|
1264
1377
|
});
|
|
@@ -1280,7 +1393,7 @@ var WebSocketClientTransport = class extends ClientTransport {
|
|
|
1280
1393
|
};
|
|
1281
1394
|
});
|
|
1282
1395
|
const conn = new WebSocketConnection(ws);
|
|
1283
|
-
log?.info(`raw websocket to ${to} ok, starting handshake`, {
|
|
1396
|
+
this.log?.info(`raw websocket to ${to} ok, starting handshake`, {
|
|
1284
1397
|
clientId: this.clientId,
|
|
1285
1398
|
connectedTo: to
|
|
1286
1399
|
});
|