rivetkit 0.0.0-sqlite-sync-3-0-0-release.14341d0 → 0.0.0-sqlite-query-metrics-v2.f5d3605
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/browser/client.d.ts +59 -99
- package/dist/browser/client.js +33 -227
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +2 -1
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/{chunk-AIGW2SKA.js → chunk-3URZ4UV5.js} +2 -2
- package/dist/tsup/{chunk-WCVYMFWJ.js → chunk-D4G35VTO.js} +4 -4
- package/dist/tsup/{chunk-NE5CUQRN.cjs → chunk-DDS7OOVF.cjs} +179 -360
- package/dist/tsup/chunk-DDS7OOVF.cjs.map +1 -0
- package/dist/tsup/{chunk-PW6FYEIV.cjs → chunk-DHL2M2E2.cjs} +3 -3
- package/dist/tsup/{chunk-PW6FYEIV.cjs.map → chunk-DHL2M2E2.cjs.map} +1 -1
- package/dist/tsup/{chunk-X32L7FDD.js → chunk-E2CUROR3.js} +2 -2
- package/dist/tsup/{chunk-SLICBKAU.js → chunk-EPRA2TCT.js} +2 -2
- package/dist/tsup/{chunk-OX5MX7TO.js → chunk-F7IGTKGM.js} +2 -2
- package/dist/tsup/{chunk-XAY2HIZN.cjs → chunk-FYDB45YU.cjs} +10 -10
- package/dist/tsup/{chunk-XAY2HIZN.cjs.map → chunk-FYDB45YU.cjs.map} +1 -1
- package/dist/tsup/{chunk-WX3JS4XU.cjs → chunk-HO76AEDH.cjs} +3 -3
- package/dist/tsup/{chunk-WX3JS4XU.cjs.map → chunk-HO76AEDH.cjs.map} +1 -1
- package/dist/tsup/{chunk-A2CF6PFH.js → chunk-JI6GZ2C2.js} +1 -18
- package/dist/tsup/chunk-JI6GZ2C2.js.map +1 -0
- package/dist/tsup/{chunk-HU4F7H3F.cjs → chunk-JW2WPE6Z.cjs} +4 -4
- package/dist/tsup/{chunk-HU4F7H3F.cjs.map → chunk-JW2WPE6Z.cjs.map} +1 -1
- package/dist/tsup/{chunk-4H2LT2WB.cjs → chunk-KDT56V3Y.cjs} +11 -10
- package/dist/tsup/chunk-KDT56V3Y.cjs.map +1 -0
- package/dist/tsup/{chunk-JNJEWQZL.js → chunk-KSP3NXGY.js} +3 -3
- package/dist/tsup/{chunk-PSIBTOAR.cjs → chunk-L3Z3W44Q.cjs} +3 -3
- package/dist/tsup/{chunk-PSIBTOAR.cjs.map → chunk-L3Z3W44Q.cjs.map} +1 -1
- package/dist/tsup/{chunk-RTWH3AX3.cjs → chunk-MYWZCDML.cjs} +2 -19
- package/dist/tsup/chunk-MYWZCDML.cjs.map +1 -0
- package/dist/tsup/{chunk-2EQ2WCO7.js → chunk-PJ5EXY6F.js} +38 -219
- package/dist/tsup/chunk-PJ5EXY6F.js.map +1 -0
- package/dist/tsup/{chunk-6WYQ3NJI.cjs → chunk-QR6EAWEC.cjs} +7 -7
- package/dist/tsup/{chunk-6WYQ3NJI.cjs.map → chunk-QR6EAWEC.cjs.map} +1 -1
- package/dist/tsup/{chunk-6ZJX3KXW.js → chunk-USKGKQZM.js} +11 -10
- package/dist/tsup/chunk-USKGKQZM.js.map +1 -0
- package/dist/tsup/client/mod.cjs +6 -6
- package/dist/tsup/client/mod.d.cts +3 -15
- package/dist/tsup/client/mod.d.ts +3 -15
- package/dist/tsup/client/mod.js +5 -5
- package/dist/tsup/common/log.cjs +2 -2
- package/dist/tsup/common/log.js +1 -1
- package/dist/tsup/common/websocket.cjs +3 -3
- package/dist/tsup/common/websocket.js +2 -2
- package/dist/tsup/{config-DK144OAw.d.cts → config-CkmVg2fG.d.cts} +12 -58
- package/dist/tsup/{config-B4erdavw.d.ts → config-Cw_BwH_G.d.ts} +12 -58
- package/dist/tsup/{config-BfG1qpYz.d.ts → config-D4clT6mq.d.cts} +52 -34
- package/dist/tsup/{config-BfG1qpYz.d.cts → config-D4clT6mq.d.ts} +52 -34
- package/dist/tsup/{context-Oxi6YWcG.d.ts → context-BYOKTQJi.d.ts} +2 -2
- package/dist/tsup/{context-Cvnf3BRe.d.cts → context-_xIcgBnE.d.cts} +2 -2
- package/dist/tsup/db/drizzle.cjs +2 -2
- package/dist/tsup/db/drizzle.d.cts +1 -1
- package/dist/tsup/db/drizzle.d.ts +1 -1
- package/dist/tsup/db/drizzle.js +1 -1
- package/dist/tsup/db/mod.cjs +3 -3
- package/dist/tsup/db/mod.d.cts +2 -2
- package/dist/tsup/db/mod.d.ts +2 -2
- package/dist/tsup/db/mod.js +2 -2
- package/dist/tsup/dynamic/mod.d.cts +2 -2
- package/dist/tsup/dynamic/mod.d.ts +2 -2
- package/dist/tsup/inspector/mod.cjs +5 -5
- package/dist/tsup/inspector/mod.js +4 -4
- package/dist/tsup/inspector/workflow.cjs +4 -4
- package/dist/tsup/inspector/workflow.js +3 -3
- package/dist/tsup/inspector-tab/mod.d.cts +3 -3
- package/dist/tsup/inspector-tab/mod.d.ts +3 -3
- package/dist/tsup/mod.cjs +203 -554
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +4 -4
- package/dist/tsup/mod.d.ts +4 -4
- package/dist/tsup/mod.js +118 -469
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +7 -7
- package/dist/tsup/test/mod.d.cts +2 -2
- package/dist/tsup/test/mod.d.ts +2 -2
- package/dist/tsup/test/mod.js +5 -5
- package/dist/tsup/unstable/migrations.d.cts +1 -1
- package/dist/tsup/unstable/migrations.d.ts +1 -1
- package/dist/tsup/utils.cjs +2 -2
- package/dist/tsup/utils.js +1 -1
- package/dist/tsup/workflow/mod.cjs +17 -17
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +4 -4
- package/dist/tsup/workflow/mod.d.ts +4 -4
- package/dist/tsup/workflow/mod.js +5 -5
- package/package.json +10 -9
- package/src/actor/config.test.ts +78 -0
- package/src/actor/keys.test.ts +275 -0
- package/src/actor/keys.ts +0 -86
- package/src/actor/utils.test.ts +48 -0
- package/src/client/actor-conn.ts +24 -136
- package/src/client/actor-handle.ts +3 -21
- package/src/client/client.ts +0 -6
- package/src/client/config.ts +1 -12
- package/src/client/lifecycle-errors.ts +1 -29
- package/src/client/test.ts +44 -0
- package/src/client/token-provider.test.ts +86 -0
- package/src/client/utils.ts +2 -13
- package/src/common/database/config.ts +52 -46
- package/src/common/database/mod.test.ts +364 -0
- package/src/common/database/native-database.test.ts +220 -0
- package/src/common/database/native-database.ts +27 -247
- package/src/common/inline-websocket-adapter.test.ts +51 -0
- package/src/common/router.ts +1 -1
- package/src/db/drizzle.test.ts +164 -0
- package/src/db/mod.ts +1 -0
- package/src/engine-api/actors.ts +3 -3
- package/src/engine-client/actor-websocket-client.ts +2 -4
- package/src/engine-client/api-endpoints.ts +14 -44
- package/src/engine-client/mod.ts +2 -2
- package/src/registry/config/envoy.ts +1 -1
- package/src/registry/config/index.test.ts +25 -0
- package/src/registry/config/index.ts +31 -29
- package/src/registry/index.ts +21 -66
- package/src/registry/napi-runtime.ts +3 -82
- package/src/registry/native.ts +52 -184
- package/src/registry/run-handler-coordinator.test.ts +252 -0
- package/src/registry/runtime.test.ts +124 -0
- package/src/registry/runtime.ts +10 -79
- package/src/registry/wasm-runtime.ts +3 -94
- package/src/unstable/migrations.test.ts +170 -0
- package/src/utils/endpoint-parser.test.ts +206 -0
- package/src/utils/env-vars.ts +10 -15
- package/src/utils.test.ts +34 -0
- package/src/workflow/driver.test.ts +62 -0
- package/dist/tsup/chunk-2EQ2WCO7.js.map +0 -1
- package/dist/tsup/chunk-4H2LT2WB.cjs.map +0 -1
- package/dist/tsup/chunk-6ZJX3KXW.js.map +0 -1
- package/dist/tsup/chunk-A2CF6PFH.js.map +0 -1
- package/dist/tsup/chunk-NE5CUQRN.cjs.map +0 -1
- package/dist/tsup/chunk-RTWH3AX3.cjs.map +0 -1
- package/src/client/retry-budget.ts +0 -78
- /package/dist/tsup/{chunk-AIGW2SKA.js.map → chunk-3URZ4UV5.js.map} +0 -0
- /package/dist/tsup/{chunk-WCVYMFWJ.js.map → chunk-D4G35VTO.js.map} +0 -0
- /package/dist/tsup/{chunk-X32L7FDD.js.map → chunk-E2CUROR3.js.map} +0 -0
- /package/dist/tsup/{chunk-SLICBKAU.js.map → chunk-EPRA2TCT.js.map} +0 -0
- /package/dist/tsup/{chunk-OX5MX7TO.js.map → chunk-F7IGTKGM.js.map} +0 -0
- /package/dist/tsup/{chunk-JNJEWQZL.js.map → chunk-KSP3NXGY.js.map} +0 -0
package/dist/browser/client.js
CHANGED
|
@@ -230,7 +230,7 @@ function noopNext() {
|
|
|
230
230
|
// package.json
|
|
231
231
|
var package_default = {
|
|
232
232
|
name: "rivetkit",
|
|
233
|
-
version: "0.0.0-sqlite-
|
|
233
|
+
version: "0.0.0-sqlite-query-metrics-v2.f5d3605",
|
|
234
234
|
description: "Lightweight libraries for building stateful actors on edge platforms",
|
|
235
235
|
license: "Apache-2.0",
|
|
236
236
|
keywords: [
|
|
@@ -440,6 +440,7 @@ var package_default = {
|
|
|
440
440
|
dependencies: {
|
|
441
441
|
"@hono/zod-openapi": "^1.1.5",
|
|
442
442
|
"@opentelemetry/api": "^1.1.0",
|
|
443
|
+
"@rivet-dev/services": "^0.2.3",
|
|
443
444
|
"@rivetkit/bare-ts": "^0.6.2",
|
|
444
445
|
"@rivetkit/engine-api-full": "workspace:*",
|
|
445
446
|
"@rivetkit/engine-cli": "workspace:*",
|
|
@@ -1151,22 +1152,6 @@ function deserializeActorKey(keyString) {
|
|
|
1151
1152
|
}
|
|
1152
1153
|
return parts;
|
|
1153
1154
|
}
|
|
1154
|
-
var CANONICAL_SEPARATOR = ",";
|
|
1155
|
-
var CANONICAL_EMPTY_PART = "\\0";
|
|
1156
|
-
function encodeActorKey(key) {
|
|
1157
|
-
return key.map((part) => {
|
|
1158
|
-
if (part === "") {
|
|
1159
|
-
return CANONICAL_EMPTY_PART;
|
|
1160
|
-
}
|
|
1161
|
-
return part.replace(/\\/g, "\\\\").replace(/,/g, "\\,");
|
|
1162
|
-
}).join(CANONICAL_SEPARATOR);
|
|
1163
|
-
}
|
|
1164
|
-
function actorKeyToGatewayQuery(key) {
|
|
1165
|
-
if (key.length === 0) {
|
|
1166
|
-
return void 0;
|
|
1167
|
-
}
|
|
1168
|
-
return encodeActorKey(key);
|
|
1169
|
-
}
|
|
1170
1155
|
|
|
1171
1156
|
// src/client/token-provider.ts
|
|
1172
1157
|
function isInvalidToken(group, code) {
|
|
@@ -1479,14 +1464,6 @@ var ClientConfigSchemaBase = z3.object({
|
|
|
1479
1464
|
// This is required in the client config in order to support
|
|
1480
1465
|
// `proxyWebSocket`
|
|
1481
1466
|
getUpgradeWebSocket: z3.custom().optional(),
|
|
1482
|
-
/**
|
|
1483
|
-
* Bounds retries of refused requests: `percent` retries per 100 requests (default 10), with
|
|
1484
|
-
* up to `maxTokens` banked for bursts (default 100). A refusal past the budget is thrown.
|
|
1485
|
-
*/
|
|
1486
|
-
retryBudget: z3.object({
|
|
1487
|
-
percent: z3.number().min(0).max(100).optional(),
|
|
1488
|
-
maxTokens: z3.number().int().min(0).optional()
|
|
1489
|
-
}).optional(),
|
|
1490
1467
|
/** Replaces global fetch for actor HTTP gateway requests. */
|
|
1491
1468
|
fetch: z3.custom().optional(),
|
|
1492
1469
|
/** Whether to automatically perform health checks when the client is created. */
|
|
@@ -1803,9 +1780,8 @@ function buildActorQueryGatewayUrl(endpoint, namespace, query, token, path = "",
|
|
|
1803
1780
|
return combineUrlPath(endpoint, gatewayPath);
|
|
1804
1781
|
}
|
|
1805
1782
|
function pushKeyQueryParams(params, key) {
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
params.append("rvt-key", rvtKey);
|
|
1783
|
+
if (key.length > 0) {
|
|
1784
|
+
params.append("rvt-key", key.join(","));
|
|
1809
1785
|
}
|
|
1810
1786
|
}
|
|
1811
1787
|
function pushInputQueryParam(params, input, maxInputSize) {
|
|
@@ -3894,22 +3870,17 @@ function internalClientError(message, opts) {
|
|
|
3894
3870
|
}
|
|
3895
3871
|
|
|
3896
3872
|
// src/client/utils.ts
|
|
3897
|
-
var RETRY_AFTER_SUFFIX = /^retry_after_ms=(\d+)$/;
|
|
3898
3873
|
function parseWebSocketCloseReason(reason) {
|
|
3899
|
-
const [mainPart,
|
|
3874
|
+
const [mainPart, rayId] = reason.split("#");
|
|
3900
3875
|
const [group, code] = mainPart.split(".");
|
|
3901
3876
|
if (!group || !code) {
|
|
3902
3877
|
logger2().warn({ msg: "failed to parse close reason", reason });
|
|
3903
3878
|
return void 0;
|
|
3904
3879
|
}
|
|
3905
|
-
const retryAfter = suffix?.match(RETRY_AFTER_SUFFIX);
|
|
3906
|
-
if (retryAfter) {
|
|
3907
|
-
return { group, code, retryAfterMs: Number(retryAfter[1]) };
|
|
3908
|
-
}
|
|
3909
3880
|
return {
|
|
3910
3881
|
group,
|
|
3911
3882
|
code,
|
|
3912
|
-
rayId
|
|
3883
|
+
rayId
|
|
3913
3884
|
};
|
|
3914
3885
|
}
|
|
3915
3886
|
function messageLength(message) {
|
|
@@ -4488,7 +4459,7 @@ var RemoteEngineControlClient = class {
|
|
|
4488
4459
|
datacenter: region,
|
|
4489
4460
|
name,
|
|
4490
4461
|
key: serializeActorKey(key),
|
|
4491
|
-
|
|
4462
|
+
runner_name_selector: poolName ?? this.#config.poolName,
|
|
4492
4463
|
input: actorInput ? uint8ArrayToBase64(
|
|
4493
4464
|
encodeCborCompat(actorInput)
|
|
4494
4465
|
) : void 0,
|
|
@@ -4541,7 +4512,7 @@ var RemoteEngineControlClient = class {
|
|
|
4541
4512
|
(config) => createActor(config, {
|
|
4542
4513
|
datacenter: region,
|
|
4543
4514
|
name,
|
|
4544
|
-
|
|
4515
|
+
runner_name_selector: poolName ?? this.#config.poolName,
|
|
4545
4516
|
key: serializeActorKey(key),
|
|
4546
4517
|
input: input ? uint8ArrayToBase64(
|
|
4547
4518
|
encodeCborCompat(input)
|
|
@@ -4845,56 +4816,6 @@ async function checkForSchedulingError(group, code, actorId, query, driver, rayI
|
|
|
4845
4816
|
return null;
|
|
4846
4817
|
}
|
|
4847
4818
|
|
|
4848
|
-
// src/client/retry-budget.ts
|
|
4849
|
-
var DEFAULT_PERCENT = 10;
|
|
4850
|
-
var DEFAULT_MAX_TOKENS = 100;
|
|
4851
|
-
var RetryBudget = class {
|
|
4852
|
-
#tokens;
|
|
4853
|
-
#maxTokens;
|
|
4854
|
-
#deposit;
|
|
4855
|
-
constructor(options = {}) {
|
|
4856
|
-
const percent = options.percent ?? DEFAULT_PERCENT;
|
|
4857
|
-
const maxTokens = options.maxTokens ?? DEFAULT_MAX_TOKENS;
|
|
4858
|
-
if (!(percent >= 0 && percent <= 100)) {
|
|
4859
|
-
throw new Error("retryBudget.percent must be in 0..=100");
|
|
4860
|
-
}
|
|
4861
|
-
if (!(maxTokens >= 0)) {
|
|
4862
|
-
throw new Error("retryBudget.maxTokens must be at least 0");
|
|
4863
|
-
}
|
|
4864
|
-
this.#maxTokens = maxTokens;
|
|
4865
|
-
this.#tokens = maxTokens;
|
|
4866
|
-
this.#deposit = percent / 100;
|
|
4867
|
-
}
|
|
4868
|
-
/** Credits one request sent. */
|
|
4869
|
-
deposit() {
|
|
4870
|
-
this.#tokens = Math.min(this.#maxTokens, this.#tokens + this.#deposit);
|
|
4871
|
-
}
|
|
4872
|
-
/** Spends one token. Returns `false` when the budget is spent. */
|
|
4873
|
-
tryWithdraw() {
|
|
4874
|
-
if (this.#tokens + 1e-9 < 1) {
|
|
4875
|
-
return false;
|
|
4876
|
-
}
|
|
4877
|
-
this.#tokens = Math.max(0, this.#tokens - 1);
|
|
4878
|
-
return true;
|
|
4879
|
-
}
|
|
4880
|
-
};
|
|
4881
|
-
function retryAfterMs(error) {
|
|
4882
|
-
if (!(error instanceof RivetError)) {
|
|
4883
|
-
return void 0;
|
|
4884
|
-
}
|
|
4885
|
-
const metadata = error.metadata;
|
|
4886
|
-
if (metadata === null || typeof metadata !== "object") {
|
|
4887
|
-
return void 0;
|
|
4888
|
-
}
|
|
4889
|
-
const hint = metadata.retry_after_ms;
|
|
4890
|
-
return typeof hint === "number" && hint >= 0 ? hint : void 0;
|
|
4891
|
-
}
|
|
4892
|
-
function retryDelayMs(attempt, opts) {
|
|
4893
|
-
const backoff = Math.min(opts.initialDelayMs * 2 ** attempt, opts.maxDelayMs);
|
|
4894
|
-
const jittered = backoff / 2 + Math.random() * (backoff / 2);
|
|
4895
|
-
return Math.max(jittered, opts.hintMs ?? 0);
|
|
4896
|
-
}
|
|
4897
|
-
|
|
4898
4819
|
// src/client/lifecycle-errors.ts
|
|
4899
4820
|
function* walkErrorChain(error, maxDepth = 8) {
|
|
4900
4821
|
let current = error;
|
|
@@ -4934,14 +4855,6 @@ function classifyActorError(error) {
|
|
|
4934
4855
|
}
|
|
4935
4856
|
);
|
|
4936
4857
|
}
|
|
4937
|
-
if (error.group === "ups" && error.code === "consumer_closed" || error.group === "depot" && error.code === "request_deadline_exceeded") {
|
|
4938
|
-
return buildLifecycleBoundaryInfo(
|
|
4939
|
-
"reconnect_only",
|
|
4940
|
-
"actor_error",
|
|
4941
|
-
error.message,
|
|
4942
|
-
{ group: error.group, code: error.code }
|
|
4943
|
-
);
|
|
4944
|
-
}
|
|
4945
4858
|
if (error.group === "guard" && isRetryableGuardGatewayHttpError(error.code)) {
|
|
4946
4859
|
return buildLifecycleBoundaryInfo(
|
|
4947
4860
|
"request_retry",
|
|
@@ -5080,7 +4993,6 @@ async function retryOnLifecycleBoundary(run, opts) {
|
|
|
5080
4993
|
const maxAttempts = opts?.maxAttempts ?? 5;
|
|
5081
4994
|
const initialDelayMs = opts?.initialDelayMs ?? 25;
|
|
5082
4995
|
const maxDelayMs = opts?.maxDelayMs ?? 200;
|
|
5083
|
-
opts?.budget?.deposit();
|
|
5084
4996
|
let lastError;
|
|
5085
4997
|
for (let attempt = 0; attempt < maxAttempts; attempt += 1) {
|
|
5086
4998
|
throwIfAborted(opts?.signal);
|
|
@@ -5094,14 +5006,7 @@ async function retryOnLifecycleBoundary(run, opts) {
|
|
|
5094
5006
|
if (attempt === maxAttempts - 1) {
|
|
5095
5007
|
break;
|
|
5096
5008
|
}
|
|
5097
|
-
|
|
5098
|
-
break;
|
|
5099
|
-
}
|
|
5100
|
-
const delayMs = retryDelayMs(attempt, {
|
|
5101
|
-
initialDelayMs,
|
|
5102
|
-
maxDelayMs,
|
|
5103
|
-
hintMs: retryAfterMs(error)
|
|
5104
|
-
});
|
|
5009
|
+
const delayMs = Math.min(initialDelayMs * 2 ** attempt, maxDelayMs);
|
|
5105
5010
|
await waitWithSignal(delayMs, opts?.signal);
|
|
5106
5011
|
}
|
|
5107
5012
|
}
|
|
@@ -5252,18 +5157,12 @@ function createQueueSender(senderOptions) {
|
|
|
5252
5157
|
}
|
|
5253
5158
|
|
|
5254
5159
|
// src/client/actor-conn.ts
|
|
5255
|
-
var CONNECT_TIMEOUT_MS = 2e4;
|
|
5256
|
-
function isConnectionOpenTimeout(error) {
|
|
5257
|
-
return error instanceof RivetError && error.group === "client" && error.code === "connection_open_timeout";
|
|
5258
|
-
}
|
|
5259
5160
|
var CONNECT_SYMBOL = /* @__PURE__ */ Symbol("connect");
|
|
5260
5161
|
var ActorConnRaw = class {
|
|
5261
5162
|
#disposed = false;
|
|
5262
5163
|
/* Will be aborted on dispose. */
|
|
5263
5164
|
#abortController = new AbortController();
|
|
5264
5165
|
#connStatus = "idle";
|
|
5265
|
-
/** The opening failure that stopped retries. Later actions must fail instead of queueing. */
|
|
5266
|
-
#connectionOpenError;
|
|
5267
5166
|
#actorId;
|
|
5268
5167
|
#connId;
|
|
5269
5168
|
#messageQueue = [];
|
|
@@ -5285,8 +5184,6 @@ var ActorConnRaw = class {
|
|
|
5285
5184
|
#keepNodeAliveInterval;
|
|
5286
5185
|
/** Promise used to indicate the socket has connected successfully. This will be rejected if the connection fails. */
|
|
5287
5186
|
#onOpenPromise;
|
|
5288
|
-
/** Sockets given up on by the connect timeout. Their late events are ignored. */
|
|
5289
|
-
#abandonedSockets = /* @__PURE__ */ new WeakSet();
|
|
5290
5187
|
#websocket;
|
|
5291
5188
|
#authRetryAvailable = true;
|
|
5292
5189
|
#client;
|
|
@@ -5382,8 +5279,6 @@ var ActorConnRaw = class {
|
|
|
5382
5279
|
`Invalid action call: expected an options object { name, args }, got ${typeof opts}. Use conn.actionName(...args) for the shorthand API.`
|
|
5383
5280
|
);
|
|
5384
5281
|
}
|
|
5385
|
-
if (this.#disposed) throw new ActorConnDisposed();
|
|
5386
|
-
if (this.#connectionOpenError) throw this.#connectionOpenError;
|
|
5387
5282
|
logger2().debug({ msg: "action", name: opts.name, args: opts.args });
|
|
5388
5283
|
const actionId = this.#actionIdCounter;
|
|
5389
5284
|
this.#actionIdCounter += 1;
|
|
@@ -5471,22 +5366,17 @@ var ActorConnRaw = class {
|
|
|
5471
5366
|
}
|
|
5472
5367
|
}
|
|
5473
5368
|
#connectWithRetry() {
|
|
5474
|
-
this.#connectionOpenError = void 0;
|
|
5475
5369
|
this.#setConnStatus("connecting");
|
|
5476
5370
|
pRetry2(this.#connectAndWait.bind(this), {
|
|
5477
5371
|
forever: true,
|
|
5478
5372
|
minTimeout: 250,
|
|
5479
5373
|
maxTimeout: 3e4,
|
|
5480
|
-
onFailedAttempt:
|
|
5374
|
+
onFailedAttempt: (error) => {
|
|
5481
5375
|
logger2().warn({
|
|
5482
5376
|
msg: "failed to reconnect",
|
|
5483
5377
|
attempt: error.attemptNumber,
|
|
5484
5378
|
error: stringifyError(error)
|
|
5485
5379
|
});
|
|
5486
|
-
const hintMs = retryAfterMs(error);
|
|
5487
|
-
if (hintMs !== void 0) {
|
|
5488
|
-
await new Promise((resolve) => setTimeout(resolve, hintMs));
|
|
5489
|
-
}
|
|
5490
5380
|
},
|
|
5491
5381
|
// Cancel retry if aborted
|
|
5492
5382
|
signal: this.#abortController.signal
|
|
@@ -5512,11 +5402,8 @@ var ActorConnRaw = class {
|
|
|
5512
5402
|
})
|
|
5513
5403
|
);
|
|
5514
5404
|
await this.#connectWebSocket();
|
|
5515
|
-
await this.#
|
|
5405
|
+
await this.#onOpenPromise.promise;
|
|
5516
5406
|
} catch (error) {
|
|
5517
|
-
this.#abandonCurrentSocket(
|
|
5518
|
-
isConnectionOpenTimeout(error) ? "Connect timeout" : "Connection opening failed"
|
|
5519
|
-
);
|
|
5520
5407
|
if (this.#shouldRetryConnectionOpenError(error)) {
|
|
5521
5408
|
throw error;
|
|
5522
5409
|
}
|
|
@@ -5526,7 +5413,7 @@ var ActorConnRaw = class {
|
|
|
5526
5413
|
`Failed to open connection: ${stringifyError(error)}`,
|
|
5527
5414
|
{ error: stringifyError(error) }
|
|
5528
5415
|
);
|
|
5529
|
-
this.#
|
|
5416
|
+
this.#clearQueuedMessages();
|
|
5530
5417
|
this.#rejectPendingPromises(actorError, false);
|
|
5531
5418
|
this.#dispatchActorError(actorError);
|
|
5532
5419
|
this.#setConnStatus("idle");
|
|
@@ -5537,61 +5424,10 @@ var ActorConnRaw = class {
|
|
|
5537
5424
|
this.#onOpenPromise = void 0;
|
|
5538
5425
|
}
|
|
5539
5426
|
}
|
|
5540
|
-
/**
|
|
5541
|
-
* Waits for the actor's Init on the current socket, up to {@link CONNECT_TIMEOUT_MS}. A socket
|
|
5542
|
-
* can stay connecting with no open, error or close event, as when the engine holds the
|
|
5543
|
-
* upgrade or a refused connect reports only an error. On timeout the socket is abandoned
|
|
5544
|
-
* and closed, and the retryable `client.connection_open_timeout` starts the next attempt.
|
|
5545
|
-
*/
|
|
5546
|
-
async #waitForOpen(open) {
|
|
5547
|
-
let timer;
|
|
5548
|
-
const timedOut = new Promise((_, reject) => {
|
|
5549
|
-
timer = setTimeout(() => {
|
|
5550
|
-
reject(
|
|
5551
|
-
new RivetError(
|
|
5552
|
-
"client",
|
|
5553
|
-
"connection_open_timeout",
|
|
5554
|
-
`Connection did not open within ${CONNECT_TIMEOUT_MS} ms`
|
|
5555
|
-
)
|
|
5556
|
-
);
|
|
5557
|
-
}, CONNECT_TIMEOUT_MS);
|
|
5558
|
-
});
|
|
5559
|
-
try {
|
|
5560
|
-
await Promise.race([open, timedOut]);
|
|
5561
|
-
} finally {
|
|
5562
|
-
clearTimeout(timer);
|
|
5563
|
-
}
|
|
5564
|
-
}
|
|
5565
|
-
#abandonCurrentSocket(reason) {
|
|
5566
|
-
const ws = this.#websocket;
|
|
5567
|
-
if (!ws) return;
|
|
5568
|
-
this.#websocket = void 0;
|
|
5569
|
-
this.#abandonedSockets.add(ws);
|
|
5570
|
-
logger2().debug({
|
|
5571
|
-
msg: "closing failed connection attempt",
|
|
5572
|
-
connId: this.#connId,
|
|
5573
|
-
readyState: ws.readyState,
|
|
5574
|
-
reason
|
|
5575
|
-
});
|
|
5576
|
-
try {
|
|
5577
|
-
ws.close(1e3, reason);
|
|
5578
|
-
} catch (err) {
|
|
5579
|
-
logger2().debug({
|
|
5580
|
-
msg: "failed to close abandoned websocket",
|
|
5581
|
-
error: stringifyError(err)
|
|
5582
|
-
});
|
|
5583
|
-
}
|
|
5584
|
-
}
|
|
5585
5427
|
#shouldRetryConnectionOpenError(error) {
|
|
5586
5428
|
if (error instanceof ActorConnDisposed) {
|
|
5587
5429
|
return false;
|
|
5588
5430
|
}
|
|
5589
|
-
if (isConnectionOpenTimeout(error)) {
|
|
5590
|
-
return true;
|
|
5591
|
-
}
|
|
5592
|
-
if (error instanceof RivetError && error.group === "client" && error.code === "connection_open_interrupted") {
|
|
5593
|
-
return true;
|
|
5594
|
-
}
|
|
5595
5431
|
if (error instanceof RivetError && isInvalidToken(error.group, error.code) && this.#driver.refreshAuthToken && this.#authRetryAvailable) {
|
|
5596
5432
|
this.#authRetryAvailable = false;
|
|
5597
5433
|
return true;
|
|
@@ -5651,18 +5487,14 @@ var ActorConnRaw = class {
|
|
|
5651
5487
|
});
|
|
5652
5488
|
this.#websocket = ws;
|
|
5653
5489
|
ws.addEventListener("open", () => {
|
|
5654
|
-
if (this.#websocket !== ws || this.#abandonedSockets.has(ws))
|
|
5655
|
-
return;
|
|
5656
5490
|
logger2().debug({
|
|
5657
5491
|
msg: "client websocket open",
|
|
5658
5492
|
connId: this.#connId
|
|
5659
5493
|
});
|
|
5660
5494
|
});
|
|
5661
5495
|
ws.addEventListener("message", async (ev) => {
|
|
5662
|
-
if (this.#websocket !== ws || this.#abandonedSockets.has(ws))
|
|
5663
|
-
return;
|
|
5664
5496
|
try {
|
|
5665
|
-
await this.#handleOnMessage(ev.data
|
|
5497
|
+
await this.#handleOnMessage(ev.data);
|
|
5666
5498
|
} catch (err) {
|
|
5667
5499
|
logger2().error({
|
|
5668
5500
|
msg: "error in websocket message handler",
|
|
@@ -5671,8 +5503,6 @@ var ActorConnRaw = class {
|
|
|
5671
5503
|
}
|
|
5672
5504
|
});
|
|
5673
5505
|
ws.addEventListener("close", async (ev) => {
|
|
5674
|
-
if (this.#websocket !== ws || this.#abandonedSockets.has(ws))
|
|
5675
|
-
return;
|
|
5676
5506
|
try {
|
|
5677
5507
|
await this.#handleOnClose(ev);
|
|
5678
5508
|
} catch (err) {
|
|
@@ -5683,8 +5513,6 @@ var ActorConnRaw = class {
|
|
|
5683
5513
|
}
|
|
5684
5514
|
});
|
|
5685
5515
|
ws.addEventListener("error", () => {
|
|
5686
|
-
if (this.#websocket !== ws || this.#abandonedSockets.has(ws))
|
|
5687
|
-
return;
|
|
5688
5516
|
try {
|
|
5689
5517
|
this.#handleOnError();
|
|
5690
5518
|
} catch (err) {
|
|
@@ -5750,7 +5578,7 @@ var ActorConnRaw = class {
|
|
|
5750
5578
|
});
|
|
5751
5579
|
}
|
|
5752
5580
|
/** Called by the onmessage event from drivers. */
|
|
5753
|
-
async #handleOnMessage(data
|
|
5581
|
+
async #handleOnMessage(data) {
|
|
5754
5582
|
logger2().trace({
|
|
5755
5583
|
msg: "received message",
|
|
5756
5584
|
dataType: typeof data,
|
|
@@ -5758,8 +5586,6 @@ var ActorConnRaw = class {
|
|
|
5758
5586
|
isArrayBuffer: data instanceof ArrayBuffer
|
|
5759
5587
|
});
|
|
5760
5588
|
const response = await this.#parseMessage(data);
|
|
5761
|
-
if (this.#websocket !== socket || this.#abandonedSockets.has(socket))
|
|
5762
|
-
return;
|
|
5763
5589
|
logger2().trace(
|
|
5764
5590
|
getLogMessage() ? {
|
|
5765
5591
|
msg: "parsed message",
|
|
@@ -5831,15 +5657,18 @@ var ActorConnRaw = class {
|
|
|
5831
5657
|
this.#actorResolutionState,
|
|
5832
5658
|
this.#driver
|
|
5833
5659
|
);
|
|
5834
|
-
if (this.#websocket !== socket || this.#abandonedSockets.has(socket)) {
|
|
5835
|
-
return;
|
|
5836
|
-
}
|
|
5837
5660
|
if (schedulingError) {
|
|
5838
5661
|
errorToThrow = schedulingError;
|
|
5839
5662
|
}
|
|
5840
5663
|
}
|
|
5664
|
+
if (this.#onOpenPromise) {
|
|
5665
|
+
this.#onOpenPromise.reject(errorToThrow);
|
|
5666
|
+
}
|
|
5841
5667
|
this.#invalidateActorIfStale(group, code);
|
|
5842
|
-
this.#
|
|
5668
|
+
for (const [id, inFlight] of this.#actionsInFlight.entries()) {
|
|
5669
|
+
inFlight.reject(errorToThrow);
|
|
5670
|
+
this.#actionsInFlight.delete(id);
|
|
5671
|
+
}
|
|
5843
5672
|
this.#dispatchActorError(errorToThrow);
|
|
5844
5673
|
}
|
|
5845
5674
|
} else if (response.body.tag === "ActionResponse") {
|
|
@@ -5890,8 +5719,7 @@ var ActorConnRaw = class {
|
|
|
5890
5719
|
const reason = closeEvent.reason || "";
|
|
5891
5720
|
const parsed = parseWebSocketCloseReason(reason);
|
|
5892
5721
|
if (parsed) {
|
|
5893
|
-
const { group, code, rayId
|
|
5894
|
-
const closeOptions = retryAfterMs2 === void 0 ? { rayId } : { rayId, metadata: { retry_after_ms: retryAfterMs2 } };
|
|
5722
|
+
const { group, code, rayId } = parsed;
|
|
5895
5723
|
if (isInvalidToken(group, code) && closeEvent.code === 1008 && failedSocket) {
|
|
5896
5724
|
try {
|
|
5897
5725
|
if (!await this.#driver.refreshAuthToken?.(
|
|
@@ -5913,7 +5741,7 @@ var ActorConnRaw = class {
|
|
|
5913
5741
|
group,
|
|
5914
5742
|
code,
|
|
5915
5743
|
`Connection closed: ${reason}`,
|
|
5916
|
-
|
|
5744
|
+
{ rayId }
|
|
5917
5745
|
)
|
|
5918
5746
|
);
|
|
5919
5747
|
return;
|
|
@@ -5934,7 +5762,7 @@ var ActorConnRaw = class {
|
|
|
5934
5762
|
group,
|
|
5935
5763
|
code,
|
|
5936
5764
|
`Connection closed: ${reason}`,
|
|
5937
|
-
|
|
5765
|
+
{ rayId }
|
|
5938
5766
|
);
|
|
5939
5767
|
}
|
|
5940
5768
|
} else {
|
|
@@ -5942,17 +5770,14 @@ var ActorConnRaw = class {
|
|
|
5942
5770
|
group,
|
|
5943
5771
|
code,
|
|
5944
5772
|
`Connection closed: ${reason}`,
|
|
5945
|
-
|
|
5773
|
+
{ rayId }
|
|
5946
5774
|
);
|
|
5947
5775
|
}
|
|
5948
5776
|
this.#invalidateActorIfStale(group, code);
|
|
5949
5777
|
} else {
|
|
5950
|
-
|
|
5951
|
-
|
|
5952
|
-
|
|
5953
|
-
"connection_open_interrupted",
|
|
5954
|
-
message
|
|
5955
|
-
) : new Error(message);
|
|
5778
|
+
error = new Error(
|
|
5779
|
+
`${wasClean ? "Connection closed" : "Connection lost"} (code: ${closeEvent.code}, reason: ${reason})`
|
|
5780
|
+
);
|
|
5956
5781
|
}
|
|
5957
5782
|
this.#rejectPendingPromises(error, false);
|
|
5958
5783
|
if (error instanceof RivetError) {
|
|
@@ -5968,7 +5793,6 @@ var ActorConnRaw = class {
|
|
|
5968
5793
|
}
|
|
5969
5794
|
}
|
|
5970
5795
|
#rejectPendingPromises(error, suppressUnhandled) {
|
|
5971
|
-
this.#clearQueuedMessages();
|
|
5972
5796
|
if (this.#onOpenPromise) {
|
|
5973
5797
|
if (suppressUnhandled) {
|
|
5974
5798
|
this.#onOpenPromise.promise.catch(() => {
|
|
@@ -6630,7 +6454,6 @@ var ActorHandleRaw = class {
|
|
|
6630
6454
|
#queueSendMutex = new AsyncMutex();
|
|
6631
6455
|
#currentActorInvocation;
|
|
6632
6456
|
#startCallSpan;
|
|
6633
|
-
#retryBudget;
|
|
6634
6457
|
/**
|
|
6635
6458
|
* Do not call this directly.
|
|
6636
6459
|
*
|
|
@@ -6638,7 +6461,7 @@ var ActorHandleRaw = class {
|
|
|
6638
6461
|
*
|
|
6639
6462
|
* @protected
|
|
6640
6463
|
*/
|
|
6641
|
-
constructor(client, driver, params, getParams, encoding, actorResolutionState, gatewayOptions = {}, signal, currentActorInvocation, startCallSpan
|
|
6464
|
+
constructor(client, driver, params, getParams, encoding, actorResolutionState, gatewayOptions = {}, signal, currentActorInvocation, startCallSpan) {
|
|
6642
6465
|
this.#client = client;
|
|
6643
6466
|
this.#driver = driver;
|
|
6644
6467
|
this.#encoding = encoding;
|
|
@@ -6649,7 +6472,6 @@ var ActorHandleRaw = class {
|
|
|
6649
6472
|
this.#signal = signal;
|
|
6650
6473
|
this.#currentActorInvocation = currentActorInvocation;
|
|
6651
6474
|
this.#startCallSpan = startCallSpan;
|
|
6652
|
-
this.#retryBudget = retryBudget;
|
|
6653
6475
|
}
|
|
6654
6476
|
async #resolveConnectionParams() {
|
|
6655
6477
|
if (this.#getParams) {
|
|
@@ -6666,7 +6488,6 @@ var ActorHandleRaw = class {
|
|
|
6666
6488
|
let useQueryTarget = isDynamicActorQuery(
|
|
6667
6489
|
this.#actorResolutionState
|
|
6668
6490
|
);
|
|
6669
|
-
this.#retryBudget.deposit();
|
|
6670
6491
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
6671
6492
|
let actorId;
|
|
6672
6493
|
try {
|
|
@@ -6700,17 +6521,8 @@ var ActorHandleRaw = class {
|
|
|
6700
6521
|
metadata,
|
|
6701
6522
|
attempt,
|
|
6702
6523
|
maxAttempts
|
|
6703
|
-
)
|
|
6704
|
-
await
|
|
6705
|
-
(resolve) => setTimeout(
|
|
6706
|
-
resolve,
|
|
6707
|
-
retryDelayMs(attempt, {
|
|
6708
|
-
initialDelayMs: 25,
|
|
6709
|
-
maxDelayMs: 1e3,
|
|
6710
|
-
hintMs: retryAfterMs(err)
|
|
6711
|
-
})
|
|
6712
|
-
)
|
|
6713
|
-
);
|
|
6524
|
+
)) {
|
|
6525
|
+
await this.#waitForRetryWindow();
|
|
6714
6526
|
continue;
|
|
6715
6527
|
}
|
|
6716
6528
|
if (await this.#shouldRetrySchedulingError(
|
|
@@ -6785,10 +6597,7 @@ var ActorHandleRaw = class {
|
|
|
6785
6597
|
if (opts.name === "destroy") {
|
|
6786
6598
|
return await run();
|
|
6787
6599
|
}
|
|
6788
|
-
return await retryOnLifecycleBoundary(run, {
|
|
6789
|
-
signal,
|
|
6790
|
-
budget: this.#retryBudget
|
|
6791
|
-
});
|
|
6600
|
+
return await retryOnLifecycleBoundary(run, { signal });
|
|
6792
6601
|
};
|
|
6793
6602
|
if (!call) {
|
|
6794
6603
|
return await send();
|
|
@@ -7328,7 +7137,6 @@ var ClientRaw = class {
|
|
|
7328
7137
|
#gatewayOptions;
|
|
7329
7138
|
#currentActorInvocation;
|
|
7330
7139
|
#startCallSpan;
|
|
7331
|
-
#retryBudget;
|
|
7332
7140
|
/**
|
|
7333
7141
|
* Creates an instance of Client.
|
|
7334
7142
|
*/
|
|
@@ -7341,7 +7149,6 @@ var ClientRaw = class {
|
|
|
7341
7149
|
this.#gatewayOptions = options.gateway ?? {};
|
|
7342
7150
|
this.#currentActorInvocation = options.currentActorInvocation;
|
|
7343
7151
|
this.#startCallSpan = options.startCallSpan;
|
|
7344
|
-
this.#retryBudget = new RetryBudget(options.retryBudget);
|
|
7345
7152
|
}
|
|
7346
7153
|
/**
|
|
7347
7154
|
* Gets a stateless handle to a actor by its ID.
|
|
@@ -7499,8 +7306,7 @@ var ClientRaw = class {
|
|
|
7499
7306
|
this.#gatewayOptions,
|
|
7500
7307
|
signal,
|
|
7501
7308
|
this.#currentActorInvocation,
|
|
7502
|
-
this.#startCallSpan
|
|
7503
|
-
this.#retryBudget
|
|
7309
|
+
this.#startCallSpan
|
|
7504
7310
|
);
|
|
7505
7311
|
}
|
|
7506
7312
|
[CREATE_ACTOR_CONN_PROXY](conn) {
|