Skip to content

Commit

Permalink
Stop racing secret uploads
Browse files Browse the repository at this point in the history
For up to date versions of wrangler, secrets are uploaded via the
'secret:bulk' command, which batches updates in a single API call.

For versions of wrangler without that capability, the action falls back
to the single 'secret put' command for each secret. It races all these
with a Promise.all()

Unfortunately, the single secret API cannot handle concurrency - at
best, these calls have to wait on one another, holding requests open
all the while. Often it times out and errors.

This fixes the legacy secret upload errors by making these calls
serially instead of concurrently.
  • Loading branch information
matthewdavidrodgers committed Apr 26, 2024
1 parent 8890678 commit 31a6263
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
13 changes: 13 additions & 0 deletions .changeset/funny-boats-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"wrangler-action": minor
---

Stop racing secret uploads

For up to date versions of wrangler, secrets are uploaded via the 'secret:bulk' command, which batches updates in a single API call.

For versions of wrangler without that capability, the action falls back to the single 'secret put' command for each secret. It races all these with a Promise.all()

Unfortunately, the single secret API cannot handle concurrency - at best, these calls have to wait on one another, holding requests open all the while. Often it times out and errors.

This fixes the legacy secret upload errors by making these calls serially instead of concurrently.
26 changes: 12 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,24 +152,22 @@ function getEnvVar(envVar: string) {
return value;
}

function legacyUploadSecrets(
async function legacyUploadSecrets(
secrets: string[],
environment?: string,
workingDirectory?: string,
) {
return Promise.all(
secrets.map((secret) => {
const args = ["wrangler", "secret", "put", secret];
if (environment) {
args.push("--env", environment);
}
return exec(packageManager.exec, args, {
cwd: workingDirectory,
silent: config["QUIET_MODE"],
input: Buffer.from(getSecret(secret)),
});
}),
);
for (const secret of secrets) {
const args = ["wrangler", "secret", "put", secret];
if (environment) {
args.push("--env", environment);
}
await exec(packageManager.exec, args, {
cwd: workingDirectory,
silent: config["QUIET_MODE"],
input: Buffer.from(getSecret(secret)),
});
}
}

async function uploadSecrets() {
Expand Down

0 comments on commit 31a6263

Please sign in to comment.