Skip to content

Commit

Permalink
Attempt fixing argon2 hashing
Browse files Browse the repository at this point in the history
It seems like something changed with workerd that caused
the `await wasi.start()` method to start throwing errors like
"The script will never generate a response"

Maybe wasi.start is no longer a promise due to new wasm
optimizations? Just a guess. Having it await the wasi start
along with the stderr and stdout streams seems to resolve the error.
  • Loading branch information
rmarscher committed Feb 12, 2024
1 parent 93c8ee3 commit 4372cb8
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/api/src/utils/password/argon2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ export async function invoke(args: string[]) {
const instance = new WebAssembly.Instance(argon2, {
wasi_snapshot_preview1: wasi.wasiImport,
})
await wasi.start(instance)
const errors = await stderr.readable.getReader().read()
const errorsValue = new TextDecoder().decode(errors.value)
const promise = wasi.start(instance)
const errors = stderr.readable.getReader().read()
const ret = stdout.readable.getReader().read()
const [errorsStream, resultStream, _] = await Promise.all([errors, ret, promise])
const errorsValue = new TextDecoder().decode(errorsStream.value)
if (errorsValue) {
throw new Error(errorsValue)
}
const ret = await stdout.readable.getReader().read()
const retValue = new TextDecoder().decode(ret.value)
const retValue = new TextDecoder().decode(resultStream.value)
return retValue.trim()
}

Expand Down

0 comments on commit 4372cb8

Please sign in to comment.