Skip to content

fix: fix race condition in embed and diffusion download utilities#1052

Closed
gianni-cor wants to merge 1 commit into
tetherto:mainfrom
gianni-cor:fix/download-race-embed-diffusion
Closed

fix: fix race condition in embed and diffusion download utilities#1052
gianni-cor wants to merge 1 commit into
tetherto:mainfrom
gianni-cor:fix/download-race-embed-diffusion

Conversation

@gianni-cor

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

The embed and diffusion packages have the same download utility race conditions that were fixed in the LLM package by PR #1019:

  • qvac-lib-infer-llamacpp-embed/examples/utils.js: Had all the original bugs — fire-and-forget fs.unlink, only handled 301/302, no double-settlement guards, no fileStream/response error handlers
  • qvac-lib-infer-llamacpp-embed/test/integration/utils.js: Fire-and-forget fs.unlink, no safeResolve/safeReject guards, no error handlers, used finish instead of close
  • lib-infer-diffusion/test/integration/utils.js: Manual startsWith('/') redirect handling instead of new URL() constructor

How does it solve it?

Port the proven download pattern from the LLM package (PR #1019):

  • Wait for fs.unlink callback before recursing on redirect
  • Add safeResolve/safeReject guards to prevent double settlement
  • Handle 307/308 redirects in embed examples/utils.js
  • Add fileStream.on('error') and response.on('error') handlers
  • Use new URL(location, base).href for safer redirect resolution
  • Use close event instead of finish for write completion

How was it tested?

Code review — the changes are identical to the pattern already battle-tested in qvac-lib-infer-llamacpp-llm/test/integration/utils.js and validated end-to-end in PR #1019.

Made with Cursor

Port the proven download pattern from the LLM package (PR #1019):
- Wait for fs.unlink callback before recursing on redirect
- Add safeResolve/safeReject guards to prevent double settlement
- Handle 307/308 redirects in embed examples/utils.js
- Add fileStream and response error handlers
- Use URL constructor for safer redirect resolution
- Use close event instead of finish for write completion

Made-with: Cursor
@gianni-cor gianni-cor requested review from a team as code owners March 20, 2026 11:59
@gianni-cor gianni-cor closed this Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant