Skip to content

Commit 925927b

Browse files
committed
fix: validate message partition ID against partition session ID for consistency
Signed-off-by: Vladislav Polyakov <[email protected]>
1 parent 1415b94 commit 925927b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

packages/topic/src/reader.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,12 @@ export class TopicReader<Payload = Uint8Array> implements Disposable {
935935
throw new Error(`Partition session with id ${msg.partitionSessionId} not found.`);
936936
}
937937

938+
// Ensure the message's partition ID matches the partition session's partition ID
939+
// This is crucial for consistency, as messages must be committed to the correct partition
940+
if (msg.partitionId !== partitionSession.partitionId) {
941+
throw new Error(`Message partitionId ${msg.partitionId} does not match partition session partitionId ${partitionSession.partitionId}.`);
942+
}
943+
938944
// Initialize empty array for this partition if it doesn't exist yet
939945
if (!offsets.has(partitionSession.partitionSessionId)) {
940946
offsets.set(partitionSession.partitionSessionId, []);

0 commit comments

Comments
 (0)