Skip to content

Shut down background cache workers on file close - #2069

Merged
martindurant merged 2 commits into
fsspec:masterfrom
Sanjays2402:fix/background-cache-shutdown
Jul 28, 2026
Merged

Shut down background cache workers on file close#2069
martindurant merged 2 commits into
fsspec:masterfrom
Sanjays2402:fix/background-cache-shutdown

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

Closing an AbstractBufferedFile currently discards its BackgroundBlockCache without stopping the executor. Its UpdatableLRU also retains a bound cache method, so repeated background-cached reads can retain workers, files, and cached blocks until cyclic GC runs.

This adds idempotent shutdown that cancels pending prefetch work, joins the executor, and breaks the reference cycle before the buffered file drops the cache. The regression test fails on master because the executor still accepts work after close() and passes once the cache is released.

Fixes #2008.

BackgroundBlockCache executors and their pending prefetches survived when a
buffered file discarded its cache. Close the cache first, stop its executor,
and break the bound-method reference cycle so the file can be released.

Add a regression test that verifies closed files reject new background work.

Fixes fsspec#2008
Comment thread fsspec/spec.py Outdated
@martindurant
martindurant merged commit 33e6da3 into fsspec:master Jul 28, 2026
11 checks passed
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.

Proper Shutdown of BackgroundBlock Cache is required

2 participants