fix(internal/fs): destroy unsynced temp files on handle release to prevent disk leak - #5070
PranjalC100 wants to merge 3 commits into
Conversation
…le release Destroy unsynced/abandoned anonymous temp files (f.content) in DeRegisterFileHandle when the last write handle is closed (writeHandleCount == 0), preventing local disk space leaks on failed writes, flush errors, or when kernel writeback cache skips FUSE_FLUSH. Fixes #4896
…le close Covers: 1. Streaming writes enabled with random/out-of-order write fallback to temp file 2. Streaming writes disabled with staged writes / kernel writeback cache 3. Multiple concurrent write handles on the same inode
There was a problem hiding this comment.
Code Review
This pull request updates the DeRegisterFileHandle method in internal/fs/inode/file.go to destroy and clean up any unsynced or abandoned temporary files (f.content) when the write handle count drops to zero, provided that local file caching is disabled. This ensures that disk space is reclaimed immediately. Additionally, comprehensive unit tests have been added in internal/fs/inode/file_test.go to verify this cleanup behavior under various scenarios, including streaming writes, staged writes, and multiple concurrent write handles. There are no review comments to address, and we have no further feedback to provide.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5070 +/- ##
==========================================
- Coverage 86.87% 86.87% -0.01%
==========================================
Files 176 176
Lines 18839 18846 +7
==========================================
+ Hits 16367 16373 +6
- Misses 2471 2472 +1
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Description
When writeback cache is enabled (
-o writeback_cache, e.g. with--enable-streaming-writes=false) or when streaming writes falls back to staged temp files during out-of-order/random writes, an I/O error or quota failure during write causes the Linux FUSE kernel driver to flagAS_EIOon the address space mapping. Onclose(), the kernel'sfuse_flush()detects this viafilemap_check_errors()and returns early without sendingFUSE_FLUSHto userspace.Previously, GCSFuse only cleaned up
f.content(the staging temporary file) inupdateInodeStateAfterSync()(successful sync) orFileInode.Destroy()(upon receivingForgetInodeOp). BecauseFUSE_FLUSHwas bypassed andForgetInoderelies on unpredictable dentry cache eviction, the open staging file remained on disk in--temp-dir, causing an indefinite disk space leak.Link to the issue in case of a bug fix.
Fixes #4896
Testing details
internal/fs/inode/file_test.go:TestDeRegisterFileHandleTestTempFileCleanup_StreamingWritesEnabled_RandomWriteFallbackTestTempFileCleanup_StreamingWritesDisabled_StagedWritesTestTempFileCleanup_MultipleWriteHandlesinternal/fs/inode/file_mock_bucket_test.go:TestDeRegisterFileHandle_DestroysContentOnLastHandleWithoutSyncinggo test -race ./internal/fs/inode/...(passed)Any backward incompatible change? If so, please explain.
N/A