Skip to content

Comments

task/fs/encryptToArchive(): fix race condition#1752

Open
alxndrsn wants to merge 4 commits intogetodk:masterfrom
alxndrsn:encrypt-race
Open

task/fs/encryptToArchive(): fix race condition#1752
alxndrsn wants to merge 4 commits intogetodk:masterfrom
alxndrsn:encrypt-race

Conversation

@alxndrsn
Copy link
Contributor

@alxndrsn alxndrsn commented Feb 15, 2026

Noted while investigating getodk/central#1645.

Defer promise resolution until destination stream has completed. Previously, Promise.resolve() was called when the source stream completed.

Fixes the following when trying to decrypt the zip file too quickly after await encryptToArchive() returned:

Error: End of central directory record signature not found. Either not a zip file, or file is truncated.
 at node_modules/yauzl/index.js:190:14
 at node_modules/yauzl/index.js:772:5
 at node_modules/yauzl/fd-slicer.js:33:7
 at FSReqCallback.wrapper [as oncomplete] (node:fs:669:5)

What has been done to verify that this works as intended?

Ran tests with & without this fix a few thousand times:

Added a test.

Why is this the best possible solution? Were any other approaches considered?

No other approaches were considered.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

This is a bug fix, but hopefully the bug is infrequent.

Does this change require updates to the API documentation? If so, please update docs/api.yaml as part of this PR.

No.

Before submitting this PR, please make sure you have:

  • run make test and confirmed all checks still pass OR confirm CircleCI build passes
  • verified that any code from external sources are properly credited in comments or that everything is internally sourced

Noted while investigating getodk/central#1645.

Defer promise resolution until destination stream has completed.  Previously, `Promise.resolve()` was called when the source stream completed.

Fixes the following when trying to decrypt the zip file too quickly after `await encryptToArchive()` returned:

	Error: End of central directory record signature not found. Either not a zip file, or file is truncated.
	 at node_modules/yauzl/index.js:190:14
	 at node_modules/yauzl/index.js:772:5
	 at node_modules/yauzl/fd-slicer.js:33:7
	 at FSReqCallback.wrapper [as oncomplete] (node:fs:669:5)
@alxndrsn alxndrsn changed the title lib/task/fs/encryptToArchive(): fix race condition task/fs/encryptToArchive(): fix race condition Feb 15, 2026
@alxndrsn alxndrsn marked this pull request as draft February 15, 2026 12:39
@alxndrsn alxndrsn marked this pull request as ready for review February 16, 2026 16:31
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