Skip to content

fix(internal/fs): destroy unsynced temp files on handle release to prevent disk leak - #5070

Draft
PranjalC100 wants to merge 3 commits into
masterfrom
fix-temp-file-leak-issue-4896
Draft

PranjalC100 wants to merge 3 commits into
masterfrom
fix-temp-file-leak-issue-4896

Conversation

@PranjalC100

@PranjalC100 PranjalC100 commented Sep 1, 2026

Copy link
Copy Markdown
Member

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 flag AS_EIO on the address space mapping. On close(), the kernel's fuse_flush() detects this via filemap_check_errors() and returns early without sending FUSE_FLUSH to userspace.

Previously, GCSFuse only cleaned up f.content (the staging temporary file) in updateInodeStateAfterSync() (successful sync) or FileInode.Destroy() (upon receiving ForgetInodeOp). Because FUSE_FLUSH was bypassed and ForgetInode relies 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

  1. Manual - NA
  2. Unit tests
    • Added table-driven and scenario tests in internal/fs/inode/file_test.go:
      • TestDeRegisterFileHandle
      • TestTempFileCleanup_StreamingWritesEnabled_RandomWriteFallback
      • TestTempFileCleanup_StreamingWritesDisabled_StagedWrites
      • TestTempFileCleanup_MultipleWriteHandles
    • Added mock bucket test in internal/fs/inode/file_mock_bucket_test.go:
      • TestDeRegisterFileHandle_DestroysContentOnLastHandleWithoutSyncing
    • Executed full unit test suite with race detector:
      go test -race ./internal/fs/inode/... (passed)
  3. Integration tests - N/A

Any backward incompatible change? If so, please explain.

N/A

…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

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.87%. Comparing base (42afe54) to head (cfff816).
⚠️ Report is 4 commits behind head on master.

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              
Flag Coverage Δ
unittests 86.87% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@PranjalC100 PranjalC100 added execute-integration-tests Run only integration tests execute-integration-tests-on-zb To run E2E tests on zonal bucket. labels Sep 3, 2026
@PranjalC100 PranjalC100 changed the title Fix temp file leak issue 4896 fix(internal/fs): destroy unsynced temp files on handle release to prevent disk leak Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

execute-integration-tests Run only integration tests execute-integration-tests-on-zb To run E2E tests on zonal bucket.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue: Temp file disk space leak when writeback cache is enabled and FUSE_WRITE returns error

1 participant