Fix: S3Downloader concurrency races in cache writing and eviction#3301
Fix: S3Downloader concurrency races in cache writing and eviction#3301ritikraj2425 wants to merge 1 commit into
Conversation
|
|
|
Heads-up for maintainers This PR is from a fork and touches integrations whose integration tests require API keys. Affected integrations:
Please run the integration tests locally ( |
Coverage report (amazon_bedrock)Click to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
|
Hey @ritikraj2425 this is a sensitive fix that we would like to tackle internally. So thanks for the contribution but I'll close this PR |
|
No worries! Thanks for letting me know, @sjrl. Happy to help where I can! |
S3Downloadercache races cause corrupt downloads under concurrent pipeline runs #3294Proposed Changes:
This PR fixes two critical race conditions in the
S3Downloadercomponent that occur when multiple pipeline runs execute in parallel with a shared cache directory:_download_filepreviously wrote directly to the final cache path. Concurrent readers could observe a partially written file, leading to parsing errors (e.g.,PDFium: Data format error)..tmp.<uuid>) and usingpathlib.Path.replace()only once the download is complete._cleanup_cachewould identify files from other active runs as "misses" and delete them if the cache was full, leading toKeyErroror missing files for downstream components..tmp.files older than 5 minutes.How did you test it?
hatch run test:unit.test_cleanup_cache_evicts_old_filesintests/test_s3_downloader.pyto verify that stale files are still evicted while recently accessed files (the new "fresh" file) are correctly protected.hatch run fmtandhatch run test:types.Notes for the reviewer
Checklist
fix: