Skip to content

Commit da96dcc

Browse files
thomasballingerConvex, Inc.
authored andcommitted
Use Transition message IDs instead of length (#41934)
GitOrigin-RevId: 110d02d4d9df591b4f400c9218e522e6bd15d598
1 parent 8902506 commit da96dcc

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

src/browser/sync/client_node.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,12 +817,14 @@ test("TransitionChunk messages are assembled into a Transition", async () => {
817817
const chunk1 = fullJson.substring(0, midpoint);
818818
const chunk2 = fullJson.substring(midpoint);
819819

820+
const transitionId = "12345";
821+
820822
send({
821823
type: "TransitionChunk",
822824
chunk: chunk1,
823825
partNumber: 0,
824826
totalParts: 2,
825-
messageLength: fullJson.length,
827+
transitionId,
826828
});
827829

828830
expect(client.getMaxObservedTimestamp()).toBeUndefined();
@@ -832,7 +834,7 @@ test("TransitionChunk messages are assembled into a Transition", async () => {
832834
chunk: chunk2,
833835
partNumber: 1,
834836
totalParts: 2,
835-
messageLength: fullJson.length,
837+
transitionId,
836838
});
837839

838840
// synchronously, it's still undefined

src/browser/sync/protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ export type TransitionChunk = {
268268
chunk: string;
269269
partNumber: number;
270270
totalParts: number;
271-
messageLength: number;
271+
transitionId: string;
272272
};
273273

274274
type MutationSuccess = {

src/browser/sync/web_socket_manager.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export class WebSocketManager {
167167
private transitionChunkBuffer: {
168168
chunks: string[];
169169
totalParts: number;
170-
messageLength: number;
170+
transitionId: string;
171171
} | null = null;
172172

173173
/** Upon HTTPS/WSS failure, the first jittered backoff duration, in ms. */
@@ -254,7 +254,7 @@ export class WebSocketManager {
254254
chunk.totalParts === 0 ||
255255
(this.transitionChunkBuffer &&
256256
(this.transitionChunkBuffer.totalParts !== chunk.totalParts ||
257-
this.transitionChunkBuffer.messageLength !== chunk.messageLength))
257+
this.transitionChunkBuffer.transitionId !== chunk.transitionId))
258258
) {
259259
// Throwing an error doesn't crash the client, so clear the buffer.
260260
this.transitionChunkBuffer = null;
@@ -265,7 +265,7 @@ export class WebSocketManager {
265265
this.transitionChunkBuffer = {
266266
chunks: [],
267267
totalParts: chunk.totalParts,
268-
messageLength: chunk.messageLength,
268+
transitionId: chunk.transitionId,
269269
};
270270
}
271271

@@ -284,11 +284,6 @@ export class WebSocketManager {
284284
const fullJson = this.transitionChunkBuffer.chunks.join("");
285285
this.transitionChunkBuffer = null;
286286

287-
if (fullJson.length !== chunk.messageLength) {
288-
throw new Error(
289-
`Assembled Transition length mismatch: expected ${chunk.messageLength}, got ${fullJson.length}`,
290-
);
291-
}
292287
const transition = parseServerMessage(JSON.parse(fullJson));
293288
if (transition.type !== "Transition") {
294289
throw new Error(

0 commit comments

Comments
 (0)