[INFRAHELP-2899] fix: address race condition in load_nested_zip() and add tests#15
Merged
Conversation
84fd64b to
4d3a673
Compare
There was a problem hiding this comment.
Pull request overview
This PR addresses a reported race condition in package_python_function/nested_zip_loader.py by serializing extraction/rename with a filesystem lock, and introduces a focused test suite to validate cold-start/warm-start behavior and concurrent imports.
Changes:
- Add an
fcntl.flock-based lockfile around nested dependency extraction/rename to prevent concurrent processes from racing. - Add
tests/test_nested_zip_loader.pyto validate extraction behavior, staging cleanup, and a basic multi-process concurrency scenario. - Remove the prior packaging/CLI test suite (
tests/test_package_python_function.py,tests/conftest.py,tests/test_local.py) and add.opencodeto.gitignore.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
package_python_function/nested_zip_loader.py |
Adds a lockfile to avoid concurrent extraction/rename races; minor formatting changes. |
tests/test_nested_zip_loader.py |
New unit tests for loader cold/warm starts, staging cleanup, and concurrency. |
tests/test_package_python_function.py |
Removed (previous end-to-end packaging/reproducibility tests). |
tests/conftest.py |
Removed (previous shared test data/fixtures for packaging tests). |
tests/test_local.py |
Removed (previous local/manual test helper). |
.gitignore |
Ignores .opencode. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
332f77b to
afe566d
Compare
ede27cc to
5b1a7f9
Compare
5b1a7f9 to
1300f00
Compare
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
BrandonLWhite
approved these changes
May 7, 2026
Owner
BrandonLWhite
left a comment
There was a problem hiding this comment.
Looks like a very good solution to the problem. Thanks!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a race condition in
nested_zip_loaderwhere, if multiple processes are trying to runload_nested_zip()a race condition could occur. Two processes would try to callos.renameat the same time, which would fail if the target_package_path was not empty.To get around this, we create a filesystem lockfile. Each time
load_nested_zip()runs, it has to acquire the lock, ensuring that concurrent unzips are impossible.A basic set of tests are also added to assert this behavior. It tests that cold starts always extract, warm starts skip the extraction step, nothing is left behind, and that multiple processes running at the same time don't create a race condition.
Note
We have to use
importlibin the tests becausenested_zip_loader.pycallsload_nested_zip()at import time. This is essential to its function and can't be worked around. Therefore, we have to do some shenanigans withimportlibto be able to actually testload_nested_zip()in isolation on test data.Finally, we fix a small bug where we never explicitly closed
zipfile.ZipFile.