Skip to content

fix(mfs): serialize FileDescriptor Flush and Close#1131

Open
lidel wants to merge 2 commits intomainfrom
fix/mfs-fd-concurrent-flush-close
Open

fix(mfs): serialize FileDescriptor Flush and Close#1131
lidel wants to merge 2 commits intomainfrom
fix/mfs-fd-concurrent-flush-close

Conversation

@lidel
Copy link
Copy Markdown
Member

@lidel lidel commented Apr 3, 2026

This PR fixes panic in MFS found in Kubo when we enabled FUSE tests on CI (log).

Flush and Close both call flushUp which accesses the underlying DagModifier without synchronization. When a caller invokes both from separate goroutines, two concurrent Sync calls race on the write buffer, causing a nil pointer dereference.

  • add sync.Mutex to fileDescriptor, acquired in Flush and Close
  • Flush on a closed descriptor now returns ErrClosed
  • add TestConcurrentFlushAndClose so we catch regressions with -race

Flush and Close both call flushUp which accesses the underlying
DagModifier without synchronization. When a caller invokes both
from separate goroutines, two concurrent Sync calls race on the
write buffer, causing a nil pointer dereference.

- add sync.Mutex to fileDescriptor, acquired in Flush and Close
- Flush on a closed descriptor now returns ErrClosed
- add TestConcurrentFlushAndClose
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 3, 2026

Codecov Report

❌ Patch coverage is 27.27273% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.49%. Comparing base (36fa06a) to head (698786d).

Files with missing lines Patch % Lines
mfs/dir.go 0.00% 16 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1131      +/-   ##
==========================================
- Coverage   62.54%   62.49%   -0.06%     
==========================================
  Files         261      261              
  Lines       26216    26238      +22     
==========================================
  Hits        16398    16398              
- Misses       8128     8151      +23     
+ Partials     1690     1689       -1     
Files with missing lines Coverage Δ
mfs/fd.go 76.19% <100.00%> (+4.39%) ⬆️
mfs/dir.go 56.49% <0.00%> (-2.68%) ⬇️

... and 8 files with indirect coverage changes

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

@lidel lidel marked this pull request as ready for review April 3, 2026 20:12
@lidel lidel requested a review from a team as a code owner April 3, 2026 20:12
Directory had SetMode/SetModTime but no matching getters, unlike
File which has both. Add Mode() and ModTime() so callers like
FUSE mounts can read directory metadata without going through
GetNode and ExtractFSNode manually.
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.

1 participant