Skip to content

Commit

Permalink
fix(GCP): Increase KMS call retries to 10
Browse files Browse the repository at this point in the history
And increase timeout to 3 seconds.

A continuation of #133 because we hit the same issue again, although it's now very rare.
  • Loading branch information
gnarea committed Feb 23, 2023
1 parent b3df326 commit ea58fe9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions src/lib/gcp/GCPPrivateKeyStore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,27 +154,27 @@ describe('Identity keys', () => {
);
});

test('Version creation call should time out after 2 seconds', async () => {
test('Version creation call should time out after 3 seconds', async () => {
const kmsClient = makeKmsClient();
const store = new GCPPrivateKeyStore(kmsClient, getDBConnection(), KMS_CONFIG);

await store.generateIdentityKeyPair();

expect(kmsClient.createCryptoKeyVersion).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({ timeout: 2_000 }),
expect.objectContaining({ timeout: 3_000 }),
);
});

test('Version creation call should be retried up to 8 times', async () => {
test('Version creation call should be retried', async () => {
const kmsClient = makeKmsClient();
const store = new GCPPrivateKeyStore(kmsClient, getDBConnection(), KMS_CONFIG);

await store.generateIdentityKeyPair();

expect(kmsClient.createCryptoKeyVersion).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({ maxRetries: 8 }),
expect.objectContaining({ maxRetries: 10 }),
);
});

Expand Down Expand Up @@ -682,7 +682,7 @@ describe('Session keys', () => {
);
});

test('Request should time out after 2 seconds', async () => {
test('Request should time out after 3 seconds', async () => {
const kmsClient = makeKMSClient();
const store = new GCPPrivateKeyStore(kmsClient, getDBConnection(), KMS_CONFIG);

Expand All @@ -694,11 +694,11 @@ describe('Session keys', () => {

expect(kmsClient.encrypt).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({ timeout: 2_000 }),
expect.objectContaining({ timeout: 3_000 }),
);
});

test('Request should be retried up to 8 times', async () => {
test('Request should be retried', async () => {
const kmsClient = makeKMSClient();
const store = new GCPPrivateKeyStore(kmsClient, getDBConnection(), KMS_CONFIG);

Expand All @@ -710,7 +710,7 @@ describe('Session keys', () => {

expect(kmsClient.encrypt).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({ maxRetries: 8 }),
expect.objectContaining({ maxRetries: 10 }),
);
});

Expand Down Expand Up @@ -918,7 +918,7 @@ describe('Session keys', () => {
);
});

test('Request should time out after 2 seconds', async () => {
test('Request should time out after 3 seconds', async () => {
const kmsClient = makeKMSClient();
const store = new GCPPrivateKeyStore(kmsClient, getDBConnection(), KMS_CONFIG);
await saveKey();
Expand All @@ -927,11 +927,11 @@ describe('Session keys', () => {

expect(kmsClient.decrypt).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({ timeout: 2_000 }),
expect.objectContaining({ timeout: 3_000 }),
);
});

test('Request should be retried up to 8 times', async () => {
test('Request should be retried', async () => {
const kmsClient = makeKMSClient();
const store = new GCPPrivateKeyStore(kmsClient, getDBConnection(), KMS_CONFIG);
await saveKey();
Expand All @@ -940,7 +940,7 @@ describe('Session keys', () => {

expect(kmsClient.decrypt).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({ maxRetries: 8 }),
expect.objectContaining({ maxRetries: 10 }),
);
});

Expand Down
8 changes: 4 additions & 4 deletions src/lib/gcp/GcpKmsRsaPssProvider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,27 +143,27 @@ describe('onSign', () => {
);
});

test('Request should time out after 2 seconds', async () => {
test('Request should time out after 3 seconds', async () => {
const kmsClient = makeKmsClient();
const provider = new GcpKmsRsaPssProvider(kmsClient);

await provider.sign(ALGORITHM, privateKey, PLAINTEXT);

expect(kmsClient.asymmetricSign).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({ timeout: 2_000 }),
expect.objectContaining({ timeout: 3_000 }),
);
});

test('Request should be retried up to 8 times', async () => {
test('Request should be retried', async () => {
const kmsClient = makeKmsClient();
const provider = new GcpKmsRsaPssProvider(kmsClient);

await provider.sign(ALGORITHM, privateKey, PLAINTEXT);

expect(kmsClient.asymmetricSign).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({ maxRetries: 8 }),
expect.objectContaining({ maxRetries: 10 }),
);
});

Expand Down
2 changes: 1 addition & 1 deletion src/lib/gcp/kmsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { wrapGCPCallError } from './gcpUtils';
* maximum number of retries before any response was received". We're working around that by
* retrying a few times.
*/
export const KMS_REQUEST_OPTIONS = { timeout: 2_000, maxRetries: 8 };
export const KMS_REQUEST_OPTIONS = { timeout: 3_000, maxRetries: 10 };

export async function retrieveKMSPublicKey(
kmsKeyVersionName: string,
Expand Down

0 comments on commit ea58fe9

Please sign in to comment.