Repository navigation
Prevent interrupted FNL downloads leaving truncated files - #87
Merged
Merged
Conversation
Downloads were written directly to their final path, so a download that was killed part way through left a truncated file behind. Subsequent runs treat existing files as complete, causing wgrib2 to fail with "read outside of file, bad grib file". Download to a .part file, verify its size against Content-Length, then atomically move it into place. Fixes #81 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
test_fetch_fnl.py:29 why testing for an empty list rather than a null |
prayner
approved these changes
Oct 10, 2026
Author
Stylistically, there is consistency with the initial test, and all the following tests: # expected file exists
assert list(tmp_path.iterdir()) == [result]
# no file exists
assert list(tmp_path.iterdir()) == []In the case of the tests where no file is expected, this check covers a lot of scenarios:
I don't mind also adding the explicit "expected file doesn't exist" assertion if you think it makes it clearer, or adding a comment to these tests. |
Author
|
Added better comments to the assertions here. |
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.
Description
Fixes #81.
The upstream FNL file for
2022-11-01 00Zis intact: a fresh download subsets cleanly withwgrib2. The failure was caused by a truncated local copy:download_filewrote directly to the final filename. Cleanup only ran on aRequestException, so a download that was killed part way (container stopped, Ctrl-C, joblib terminating workers after another download failed) left a partial file in place.setup_for_wrf.pyonly checks whether an FNL file exists before skipping its download, so subsequent runs reused the truncated file andwgrib2failed withread outside of file, bad grib file.Six truncated files were found in a local FNL cache, each roughly 35–50% of the expected size.
This PR downloads to a
<name>.partfile, verifies its size againstContent-Length(when the response isn't content-encoded), and then moves it into place withos.replace. The.partfile is always removed on failure or interruption, so the final path only ever holds a complete file.Checklist
Please confirm that this pull request has done the following:
changelog/Notes
Existing truncated files in FNL caches are not detected by this change and need to be deleted manually.
🤖 Generated with Claude Code