From bbd31b30ae106f1259ebbeafef238492a4bee77d Mon Sep 17 00:00:00 2001 From: mathis obadia Date: Thu, 22 Jun 2023 18:22:59 +0200 Subject: [PATCH] hash MessageDeduplicationId to avoid invalid values (#139) * hash MessageDeduplicationId to avoid invalid values * Sync --------- Co-authored-by: Frank --- .changeset/tame-papayas-change.md | 5 +++++ packages/open-next/src/adapters/server-adapter.ts | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .changeset/tame-papayas-change.md diff --git a/.changeset/tame-papayas-change.md b/.changeset/tame-papayas-change.md new file mode 100644 index 00000000..892bac5d --- /dev/null +++ b/.changeset/tame-papayas-change.md @@ -0,0 +1,5 @@ +--- +"open-next": patch +--- + +server: hash message dedup id diff --git a/packages/open-next/src/adapters/server-adapter.ts b/packages/open-next/src/adapters/server-adapter.ts index d7a6f04d..8805f390 100644 --- a/packages/open-next/src/adapters/server-adapter.ts +++ b/packages/open-next/src/adapters/server-adapter.ts @@ -1,4 +1,5 @@ import path from "node:path"; +import crypto from "node:crypto"; import type { APIGatewayProxyEventV2, APIGatewayProxyEvent, @@ -271,10 +272,12 @@ async function revalidateIfRequired( // your page will need to have a different etag to bypass the deduplication window. // If data has the same etag during these 5 min dedup window, it will be deduplicated and not revalidated. try { + const hash = (str: string) => crypto.createHash('md5').update(str).digest('hex') + await sqsClient.send( new SendMessageCommand({ QueueUrl: REVALIDATION_QUEUE_URL, - MessageDeduplicationId: `${rawPath}-${headers.etag}`, + MessageDeduplicationId: hash(`${rawPath}-${headers.etag}`), MessageBody: JSON.stringify({ host, url: rawPath }), MessageGroupId: "revalidate", })