Skip to content

Commit fa84161

Browse files
authored
fix(rivetkit): remove client-side connection request size check (#5057)
# Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ## How Has This Been Tested? Please describe the tests that you ran to verify your changes. ## Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes
1 parent 69fa72d commit fa84161

2 files changed

Lines changed: 25 additions & 35 deletions

File tree

rivetkit-typescript/packages/rivetkit/src/client/actor-conn.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ interface EventSubscriptions<Args extends Array<unknown>> {
9393
once: boolean;
9494
}
9595

96-
const DEFAULT_MAX_INCOMING_MESSAGE_SIZE = 65_536;
97-
9896
/**
9997
* A function that unsubscribes from an event.
10098
*
@@ -1280,34 +1278,8 @@ export class ActorConnRaw {
12801278
}
12811279
},
12821280
);
1283-
const serializedLength = messageLength(messageSerialized);
1284-
if (
1285-
serializedLength > DEFAULT_MAX_INCOMING_MESSAGE_SIZE &&
1286-
message.body.tag === "ActionRequest"
1287-
) {
1288-
const actionId = Number(message.body.val.id);
1289-
const inFlight = this.#takeActionInFlight(actionId);
1290-
const error = new errors.ActorError(
1291-
"message",
1292-
"incoming_too_long",
1293-
"Incoming message too long",
1294-
{
1295-
maxSize: DEFAULT_MAX_INCOMING_MESSAGE_SIZE,
1296-
actualSize: serializedLength,
1297-
},
1298-
);
1299-
logger().warn({
1300-
msg: "rejecting oversized connection action request",
1301-
actionId,
1302-
actionName: inFlight.name,
1303-
actualSize: serializedLength,
1304-
maxSize: DEFAULT_MAX_INCOMING_MESSAGE_SIZE,
1305-
});
1306-
inFlight.reject(error);
1307-
this.#dispatchActorError(error);
1308-
return;
1309-
}
13101281
this.#websocket.send(messageSerialized);
1282+
const serializedLength = messageLength(messageSerialized);
13111283
logger().trace({
13121284
msg: "sent websocket message",
13131285
len: serializedLength,

rivetkit-typescript/packages/rivetkit/tests/driver/actor-conn.test.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -707,30 +707,48 @@ describeDriverMatrix("Actor Conn", (driverTestConfig) => {
707707
await connection.dispose();
708708
});
709709

710-
test("should reject request exceeding maxIncomingMessageSize", async (c) => {
710+
test("should reject request exceeding maxIncomingMessageSize via server", async (c) => {
711711
const { client } = await setupDriverTest(c, driverTestConfig);
712712

713713
const handle = client.largePayloadConnActor.getOrCreate([
714714
"test-large-request-exceed",
715715
]);
716716
const connection = handle.connect();
717717

718-
// Create a payload that exceeds the default 64KB limit
719-
// Each item is roughly 60 bytes, so 1500 items ≈ 90KB
718+
// Create a payload that exceeds the default 64KB limit.
719+
// Each item is roughly 60 bytes, so 1500 items ~ 90KB.
720+
// The server enforces the limit and closes the entire
721+
// WebSocket with reason "message.incoming_too_long".
720722
const items: string[] = [];
721723
for (let i = 0; i < 1500; i++) {
722724
items.push(
723725
`Item ${i} with some additional text to increase size`,
724726
);
725727
}
726728

727-
await expect(
728-
connection.processLargeRequest({ items }),
729-
).rejects.toMatchObject({
729+
// Send a normal action concurrently with the oversized
730+
// one to verify the server closes the whole connection,
731+
// not just the offending action.
732+
const [oversizedResult, collateralResult] =
733+
await Promise.allSettled([
734+
connection.processLargeRequest({ items }),
735+
connection.processLargeRequest({
736+
items: ["small"],
737+
}),
738+
]);
739+
740+
expect(oversizedResult.status).toBe("rejected");
741+
expect(
742+
(oversizedResult as PromiseRejectedResult).reason,
743+
).toMatchObject({
730744
group: "message",
731745
code: "incoming_too_long",
732746
});
733747

748+
// The normal action also fails because the server
749+
// closed the connection.
750+
expect(collateralResult.status).toBe("rejected");
751+
734752
// Clean up
735753
await connection.dispose();
736754
});

0 commit comments

Comments
 (0)