Skip to content

fix(polly-request-presigner): not to throw when presign concurrently #2628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion packages/polly-request-presigner/src/getSignedUrls.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,17 @@ describe("getSignedUrl", () => {
expect(mockPresign).toBeCalled();
expect(mockPresign.mock.calls[0][1]).toMatchObject(options);
});
});

it("should not throw if it's called concurrently", async () => {
const mockPresigned = "a presigned url";
mockPresign.mockReturnValue(mockPresigned);
const client = new PollyClient(clientParams);
const command = new SynthesizeSpeechCommand({
Text: "hello world",
OutputFormat: "mp3",
VoiceId: "Kimberly",
});
const commands = [command, command];
return expect(Promise.all(commands.map((command) => getSignedUrl(client, command)))).resolves.toBeInstanceOf(Array);
});
});
6 changes: 4 additions & 2 deletions packages/polly-request-presigner/src/getSignedUrls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ export const getSignedUrl = async (
},
} as any;
};
const middlewareName = "presignInterceptMiddleware";

client.middlewareStack.addRelativeTo(presignInterceptMiddleware, {
name: "presignInterceptMiddleware",
name: middlewareName,
relation: "before",
toMiddleware: "awsAuthMiddleware",
override: true,
});

let presigned: HttpRequest;
Expand All @@ -63,7 +65,7 @@ export const getSignedUrl = async (
//@ts-ignore the output is faked, so it's not actually OutputType
presigned = output.presigned;
} finally {
client.middlewareStack.remove("presignInterceptMiddleware");
client.middlewareStack.remove(middlewareName);
}

return formatUrl(presigned);
Expand Down