Skip to content

Commit d8bdaa0

Browse files
MasterPtatoNathanFlurry
authored andcommitted
fix: fix connection dead
1 parent df3e3ef commit d8bdaa0

File tree

6 files changed

+48
-26
lines changed

6 files changed

+48
-26
lines changed

clients/openapi/openapi.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@
2424
"schema": {
2525
"type": "string"
2626
},
27-
"required": true,
27+
"required": false,
28+
"name": "actor_ids",
29+
"in": "query"
30+
},
31+
{
32+
"schema": {
33+
"type": "string"
34+
},
35+
"required": false,
2836
"name": "key",
2937
"in": "query"
3038
}

packages/cloudflare-workers/src/actor-handler-do.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export function createActorDurableObject(
6363
*/
6464
return class ActorHandler
6565
extends DurableObject<Bindings>
66-
implements ActorHandlerInterface {
66+
implements ActorHandlerInterface
67+
{
6768
#initialized?: InitializedData;
6869
#initializedPromise?: ReturnType<typeof promiseWithResolvers<void>>;
6970

packages/rivetkit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
"@bare-ts/lib": "~0.3.0",
164164
"@hono/standard-validator": "^0.1.3",
165165
"@hono/zod-openapi": "^0.19.10",
166-
"@rivetkit/engine-runner": "https://pkg.pr.new/rivet-dev/engine/@rivetkit/engine-runner@b72b232",
166+
"@rivetkit/engine-runner": "https://pkg.pr.new/rivet-dev/engine/@rivetkit/engine-runner@9676fe4",
167167
"@rivetkit/fast-json-patch": "^3.1.2",
168168
"cbor-x": "^1.6.0",
169169
"hono": "^4.9.8",

packages/rivetkit/src/drivers/engine/actor-driver.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import type { Client } from "@/client/client";
2222
import {
2323
PATH_CONNECT_WEBSOCKET,
2424
PATH_RAW_WEBSOCKET_PREFIX,
25+
WS_PROTOCOL_CONN_PARAMS,
26+
WS_PROTOCOL_ENCODING,
2527
} from "@/common/actor-router-consts";
2628
import type { UpgradeWebSocketArgs } from "@/common/inline-websocket-adapter2";
2729
import { getLogger } from "@/common/log";
@@ -85,6 +87,7 @@ export class EngineActorDriver implements ActorDriver {
8587
totalSlots: config.totalSlots,
8688
runnerName: config.runnerName,
8789
runnerKey: config.runnerKey,
90+
token: config.token,
8891
metadata: {
8992
inspectorToken: this.#runConfig.inspector.token(),
9093
},
@@ -293,9 +296,24 @@ export class EngineActorDriver implements ActorDriver {
293296

294297
const url = new URL(request.url);
295298

296-
// Parse headers
297-
const encodingRaw = request.headers.get(HEADER_ENCODING);
298-
const connParamsRaw = request.headers.get(HEADER_CONN_PARAMS);
299+
const protocols = request.headers.get("sec-websocket-protocol");
300+
if (protocols === null)
301+
throw new Error(`Missing sec-websocket-protocol header`);
302+
303+
let encodingRaw: string | undefined;
304+
let connParamsRaw: string | undefined;
305+
306+
// Parse protocols
307+
const protocolList = protocols.split(",").map((p) => p.trim());
308+
for (const protocol of protocolList) {
309+
if (protocol.startsWith(WS_PROTOCOL_ENCODING)) {
310+
encodingRaw = protocol.substring(WS_PROTOCOL_ENCODING.length);
311+
} else if (protocol.startsWith(WS_PROTOCOL_CONN_PARAMS)) {
312+
connParamsRaw = decodeURIComponent(
313+
protocol.substring(WS_PROTOCOL_CONN_PARAMS.length),
314+
);
315+
}
316+
}
299317

300318
const encoding = EncodingSchema.parse(encodingRaw);
301319
const connParams = connParamsRaw ? JSON.parse(connParamsRaw) : undefined;

packages/rivetkit/src/drivers/engine/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ export const ConfigSchema = z
2323
.default(
2424
() => getEnvUniversal("RIVET_RUNNER_KEY") ?? crypto.randomUUID(),
2525
),
26+
token: z
27+
.string()
28+
.optional()
29+
.transform((val) => val ?? getEnvUniversal("RIVET_TOKEN")),
2630
totalSlots: z.number().default(100_000),
2731
})
2832
.default({});

pnpm-lock.yaml

Lines changed: 11 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)