@replit/river 0.19.3 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-2Z2NE47H.js → chunk-5WFL722S.js} +15 -2
- package/dist/chunk-5WFL722S.js.map +1 -0
- package/dist/{chunk-LDCCELCJ.js → chunk-HGBAUTIW.js} +2 -2
- package/dist/{chunk-QZD2UTDJ.js → chunk-NYOK5VKK.js} +383 -245
- package/dist/chunk-NYOK5VKK.js.map +1 -0
- package/dist/{chunk-SLYSDRLE.js → chunk-YB5LRYL6.js} +517 -260
- package/dist/chunk-YB5LRYL6.js.map +1 -0
- package/dist/{chunk-YHKIWQOC.js → chunk-ZIWOHAQM.js} +2 -2
- package/dist/{connection-cfec12e6.d.ts → connection-d49d5d56.d.ts} +1 -1
- package/dist/{connection-aa0ea000.d.ts → connection-dba95bc8.d.ts} +1 -1
- package/dist/{index-e2513701.d.ts → index-3ac92295.d.ts} +12 -0
- package/dist/logging/index.d.cts +1 -1
- package/dist/logging/index.d.ts +1 -1
- package/dist/router/index.cjs +514 -257
- package/dist/router/index.cjs.map +1 -1
- package/dist/router/index.d.cts +4 -4
- package/dist/router/index.d.ts +4 -4
- package/dist/router/index.js +2 -2
- package/dist/{services-5fc5712d.d.ts → services-8496d6e8.d.ts} +1 -1
- package/dist/{services-4bba42d8.d.ts → services-abc077db.d.ts} +1 -1
- package/dist/transport/impls/uds/client.cjs +150 -74
- package/dist/transport/impls/uds/client.cjs.map +1 -1
- package/dist/transport/impls/uds/client.d.cts +2 -2
- package/dist/transport/impls/uds/client.d.ts +2 -2
- package/dist/transport/impls/uds/client.js +3 -3
- package/dist/transport/impls/uds/server.cjs +249 -169
- package/dist/transport/impls/uds/server.cjs.map +1 -1
- package/dist/transport/impls/uds/server.d.cts +2 -2
- package/dist/transport/impls/uds/server.d.ts +2 -2
- package/dist/transport/impls/uds/server.js +3 -3
- package/dist/transport/impls/ws/client.cjs +150 -74
- package/dist/transport/impls/ws/client.cjs.map +1 -1
- package/dist/transport/impls/ws/client.d.cts +2 -2
- package/dist/transport/impls/ws/client.d.ts +2 -2
- package/dist/transport/impls/ws/client.js +3 -3
- package/dist/transport/impls/ws/server.cjs +249 -169
- package/dist/transport/impls/ws/server.cjs.map +1 -1
- package/dist/transport/impls/ws/server.d.cts +2 -2
- package/dist/transport/impls/ws/server.d.ts +2 -2
- package/dist/transport/impls/ws/server.js +3 -3
- package/dist/transport/index.cjs +387 -243
- package/dist/transport/index.cjs.map +1 -1
- package/dist/transport/index.d.cts +3 -2
- package/dist/transport/index.d.ts +3 -2
- package/dist/transport/index.js +2 -2
- package/dist/util/testHelpers.cjs +1 -0
- package/dist/util/testHelpers.cjs.map +1 -1
- package/dist/util/testHelpers.d.cts +2 -2
- package/dist/util/testHelpers.d.ts +2 -2
- package/dist/util/testHelpers.js +3 -3
- package/package.json +2 -1
- package/dist/chunk-2Z2NE47H.js.map +0 -1
- package/dist/chunk-QZD2UTDJ.js.map +0 -1
- package/dist/chunk-SLYSDRLE.js.map +0 -1
- /package/dist/{chunk-LDCCELCJ.js.map → chunk-HGBAUTIW.js.map} +0 -0
- /package/dist/{chunk-YHKIWQOC.js.map → chunk-ZIWOHAQM.js.map} +0 -0
|
@@ -26,6 +26,7 @@ module.exports = __toCommonJS(client_exports);
|
|
|
26
26
|
|
|
27
27
|
// transport/transport.ts
|
|
28
28
|
var import_value = require("@sinclair/typebox/value");
|
|
29
|
+
var import_api2 = require("@opentelemetry/api");
|
|
29
30
|
|
|
30
31
|
// transport/message.ts
|
|
31
32
|
var import_typebox = require("@sinclair/typebox");
|
|
@@ -40,6 +41,12 @@ var TransportMessageSchema = (t) => import_typebox.Type.Object({
|
|
|
40
41
|
procedureName: import_typebox.Type.Optional(import_typebox.Type.String()),
|
|
41
42
|
streamId: import_typebox.Type.String(),
|
|
42
43
|
controlFlags: import_typebox.Type.Integer(),
|
|
44
|
+
tracing: import_typebox.Type.Optional(
|
|
45
|
+
import_typebox.Type.Object({
|
|
46
|
+
traceparent: import_typebox.Type.String(),
|
|
47
|
+
tracestate: import_typebox.Type.String()
|
|
48
|
+
})
|
|
49
|
+
),
|
|
43
50
|
payload: t
|
|
44
51
|
});
|
|
45
52
|
var ControlMessageAckSchema = import_typebox.Type.Object({
|
|
@@ -77,7 +84,7 @@ var ControlMessagePayloadSchema = import_typebox.Type.Union([
|
|
|
77
84
|
var OpaqueTransportMessageSchema = TransportMessageSchema(
|
|
78
85
|
import_typebox.Type.Unknown()
|
|
79
86
|
);
|
|
80
|
-
function handshakeRequestMessage(from, to, sessionId, metadata) {
|
|
87
|
+
function handshakeRequestMessage(from, to, sessionId, metadata, tracing) {
|
|
81
88
|
return {
|
|
82
89
|
id: (0, import_nanoid.nanoid)(),
|
|
83
90
|
from,
|
|
@@ -86,6 +93,7 @@ function handshakeRequestMessage(from, to, sessionId, metadata) {
|
|
|
86
93
|
ack: 0,
|
|
87
94
|
streamId: (0, import_nanoid.nanoid)(),
|
|
88
95
|
controlFlags: 0,
|
|
96
|
+
tracing,
|
|
89
97
|
payload: {
|
|
90
98
|
type: "HANDSHAKE_REQ",
|
|
91
99
|
protocolVersion: PROTOCOL_VERSION,
|
|
@@ -373,6 +381,11 @@ var Session = class {
|
|
|
373
381
|
}
|
|
374
382
|
};
|
|
375
383
|
|
|
384
|
+
// tracing/index.ts
|
|
385
|
+
var import_api = require("@opentelemetry/api");
|
|
386
|
+
var tracer = import_api.trace.getTracer("river");
|
|
387
|
+
var tracing_default = tracer;
|
|
388
|
+
|
|
376
389
|
// util/stringify.ts
|
|
377
390
|
function coerceErrorString(err) {
|
|
378
391
|
if (err instanceof Error) {
|
|
@@ -932,82 +945,142 @@ var ClientTransport = class extends Transport {
|
|
|
932
945
|
* @param to The client ID of the node to connect to.
|
|
933
946
|
*/
|
|
934
947
|
async connect(to) {
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
}
|
|
957
|
-
log?.info(`attempting connection to ${to} (${backoffMs}ms backoff)`, {
|
|
958
|
-
clientId: this.clientId,
|
|
959
|
-
connectedTo: to
|
|
960
|
-
});
|
|
961
|
-
this.retryBudget.consumeBudget(to);
|
|
962
|
-
reconnectPromise = sleep.then(() => {
|
|
963
|
-
if (!canProceedWithConnection()) {
|
|
964
|
-
throw new Error("transport state is no longer open");
|
|
948
|
+
return tracing_default.startActiveSpan(
|
|
949
|
+
"connect",
|
|
950
|
+
{
|
|
951
|
+
attributes: {
|
|
952
|
+
component: "river",
|
|
953
|
+
"span.kind": "client"
|
|
954
|
+
},
|
|
955
|
+
kind: import_api2.SpanKind.CLIENT
|
|
956
|
+
},
|
|
957
|
+
async (span) => {
|
|
958
|
+
try {
|
|
959
|
+
await this.connectAttempt(to);
|
|
960
|
+
} catch (e) {
|
|
961
|
+
if (e instanceof Error) {
|
|
962
|
+
span.recordException(e);
|
|
963
|
+
} else {
|
|
964
|
+
span.recordException(coerceErrorString(e));
|
|
965
|
+
}
|
|
966
|
+
span.setStatus({ code: import_api2.SpanStatusCode.ERROR });
|
|
967
|
+
} finally {
|
|
968
|
+
span.end();
|
|
965
969
|
}
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
970
|
+
}
|
|
971
|
+
);
|
|
972
|
+
}
|
|
973
|
+
async connectAttempt(to, attempt = 0) {
|
|
974
|
+
const retry = await tracing_default.startActiveSpan(
|
|
975
|
+
"connect",
|
|
976
|
+
{
|
|
977
|
+
attributes: {
|
|
978
|
+
component: "river",
|
|
979
|
+
"river.attempt": attempt,
|
|
980
|
+
"span.kind": "client"
|
|
981
|
+
},
|
|
982
|
+
kind: import_api2.SpanKind.CLIENT
|
|
983
|
+
},
|
|
984
|
+
async (span) => {
|
|
985
|
+
try {
|
|
986
|
+
const canProceedWithConnection = () => this.state === "open";
|
|
987
|
+
if (!canProceedWithConnection()) {
|
|
988
|
+
log?.info(
|
|
989
|
+
`transport state is no longer open, cancelling attempt to connect to ${to}`,
|
|
990
|
+
{ clientId: this.clientId, connectedTo: to }
|
|
991
|
+
);
|
|
992
|
+
return false;
|
|
993
|
+
}
|
|
994
|
+
let reconnectPromise = this.inflightConnectionPromises.get(to);
|
|
995
|
+
if (!reconnectPromise) {
|
|
996
|
+
const budgetConsumed = this.retryBudget.getBudgetConsumed(to);
|
|
997
|
+
if (!this.retryBudget.hasBudget(to)) {
|
|
998
|
+
const errMsg = `tried to connect to ${to} but retry budget exceeded (more than ${budgetConsumed} attempts in the last ${this.retryBudget.totalBudgetRestoreTime}ms)`;
|
|
999
|
+
log?.warn(errMsg, { clientId: this.clientId, connectedTo: to });
|
|
1000
|
+
this.protocolError(ProtocolError.RetriesExceeded, errMsg);
|
|
1001
|
+
return false;
|
|
974
1002
|
}
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
1003
|
+
let sleep = Promise.resolve();
|
|
1004
|
+
const backoffMs = this.retryBudget.getBackoffMs(to);
|
|
1005
|
+
if (backoffMs > 0) {
|
|
1006
|
+
sleep = new Promise((resolve) => setTimeout(resolve, backoffMs));
|
|
1007
|
+
}
|
|
1008
|
+
log?.info(
|
|
1009
|
+
`attempting connection to ${to} (${backoffMs}ms backoff)`,
|
|
1010
|
+
{
|
|
1011
|
+
clientId: this.clientId,
|
|
1012
|
+
connectedTo: to
|
|
1013
|
+
}
|
|
1014
|
+
);
|
|
1015
|
+
this.retryBudget.consumeBudget(to);
|
|
1016
|
+
reconnectPromise = sleep.then(() => {
|
|
1017
|
+
if (!canProceedWithConnection()) {
|
|
1018
|
+
throw new Error("transport state is no longer open");
|
|
1019
|
+
}
|
|
1020
|
+
}).then(() => this.createNewOutgoingConnection(to)).then((conn) => {
|
|
1021
|
+
if (!canProceedWithConnection()) {
|
|
1022
|
+
log?.info(
|
|
1023
|
+
`transport state is no longer open, closing pre-handshake connection to ${to}`,
|
|
1024
|
+
{
|
|
1025
|
+
clientId: this.clientId,
|
|
1026
|
+
connectedTo: to,
|
|
1027
|
+
connId: conn.debugId
|
|
1028
|
+
}
|
|
1029
|
+
);
|
|
1030
|
+
conn.close();
|
|
1031
|
+
throw new Error("transport state is no longer open");
|
|
1032
|
+
}
|
|
1033
|
+
return this.sendHandshake(to, conn).then((ok) => {
|
|
1034
|
+
if (!ok) {
|
|
1035
|
+
conn.close();
|
|
1036
|
+
throw new Error("failed to send handshake");
|
|
1037
|
+
}
|
|
1038
|
+
return conn;
|
|
1039
|
+
});
|
|
1040
|
+
});
|
|
1041
|
+
this.inflightConnectionPromises.set(to, reconnectPromise);
|
|
1042
|
+
} else {
|
|
1043
|
+
log?.info(
|
|
1044
|
+
`attempting connection to ${to} (reusing previous attempt)`,
|
|
1045
|
+
{
|
|
1046
|
+
clientId: this.clientId,
|
|
1047
|
+
connectedTo: to
|
|
1048
|
+
}
|
|
1049
|
+
);
|
|
983
1050
|
}
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1051
|
+
try {
|
|
1052
|
+
await reconnectPromise;
|
|
1053
|
+
} catch (error) {
|
|
1054
|
+
this.inflightConnectionPromises.delete(to);
|
|
1055
|
+
const errStr = coerceErrorString(error);
|
|
1056
|
+
if (!this.reconnectOnConnectionDrop || !canProceedWithConnection()) {
|
|
1057
|
+
log?.warn(`connection to ${to} failed (${errStr})`, {
|
|
1058
|
+
clientId: this.clientId,
|
|
1059
|
+
connectedTo: to
|
|
1060
|
+
});
|
|
1061
|
+
} else {
|
|
1062
|
+
log?.warn(`connection to ${to} failed (${errStr}), retrying`, {
|
|
1063
|
+
clientId: this.clientId,
|
|
1064
|
+
connectedTo: to
|
|
1065
|
+
});
|
|
1066
|
+
return true;
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
} catch (e) {
|
|
1070
|
+
if (e instanceof Error) {
|
|
1071
|
+
span.recordException(e);
|
|
1072
|
+
} else {
|
|
1073
|
+
span.recordException(coerceErrorString(e));
|
|
1074
|
+
}
|
|
1075
|
+
span.setStatus({ code: import_api2.SpanStatusCode.ERROR });
|
|
1076
|
+
} finally {
|
|
1077
|
+
span.end();
|
|
1078
|
+
}
|
|
1079
|
+
return false;
|
|
1010
1080
|
}
|
|
1081
|
+
);
|
|
1082
|
+
if (retry) {
|
|
1083
|
+
return this.connectAttempt(to, attempt + 1);
|
|
1011
1084
|
}
|
|
1012
1085
|
}
|
|
1013
1086
|
deleteSession(session) {
|
|
@@ -1015,6 +1088,8 @@ var ClientTransport = class extends Transport {
|
|
|
1015
1088
|
super.deleteSession(session);
|
|
1016
1089
|
}
|
|
1017
1090
|
async sendHandshake(to, conn) {
|
|
1091
|
+
const tracing = { traceparent: "", tracestate: "" };
|
|
1092
|
+
import_api2.propagation.inject(import_api2.context.active(), tracing);
|
|
1018
1093
|
let metadata;
|
|
1019
1094
|
if (this.options.handshake) {
|
|
1020
1095
|
metadata = await this.options.handshake.get();
|
|
@@ -1035,7 +1110,8 @@ var ClientTransport = class extends Transport {
|
|
|
1035
1110
|
this.clientId,
|
|
1036
1111
|
to,
|
|
1037
1112
|
session.id,
|
|
1038
|
-
metadata
|
|
1113
|
+
metadata,
|
|
1114
|
+
tracing
|
|
1039
1115
|
);
|
|
1040
1116
|
log?.debug(`sending handshake request to ${to}`, {
|
|
1041
1117
|
clientId: this.clientId,
|