Repository navigation
fix(mfs): prevent panic on concurrent flush and close - #1131
Merged
Merged
Conversation
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 Reportβ Patch coverage is
@@ Coverage Diff @@
## main #1131 +/- ##
==========================================
- Coverage 62.69% 62.68% -0.02%
==========================================
Files 262 262
Lines 26235 26257 +22
==========================================
+ Hits 16448 16458 +10
- Misses 8088 8102 +14
+ Partials 1699 1697 -2
... and 9 files with indirect coverage changes π New features to boost your workflow:
|
lidel
marked this pull request as ready for review
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.
guillaumemichel
approved these changes
Apr 7, 2026
lidel
force-pushed
the
fix/mfs-fd-concurrent-flush-close
branch
from
April 7, 2026 15:26
7cc61c7 to
3c5d8ea
Compare
lidel
added a commit
to ipfs/kubo
that referenced
this pull request
Apr 7, 2026
Picks up ipfs/boxo#1131: fix concurrent flush/close panic in MFS file descriptors (FUSE race condition).
lidel
added a commit
to ipfs/kubo
that referenced
this pull request
Apr 7, 2026
* test(deps): quick test of boxo with ipfs/boxo#1125 * test(mfs): verify CidBuilder preservation across mutations and restarts * docs(changelog): highlight MFS CidBuilder fix * fix(mfs): apply Import.CidVersion and HashFunction to MFS root The MFS root loaded at daemon startup never received a CidBuilder from config, so it stayed CIDv0/sha2-256 even with non-default Import settings. Pass the configured CidBuilder to mfs.NewRoot(). - add Import.UnixFSCidBuilder() helper for building cid.Prefix - pass WithCidBuilder to mfs.NewRoot in core/node/core.go - deduplicate getPrefixNew/getPrefix in files.go - strengthen regression test to check CID version and root dir * fix: restore explicit Flush, use upstream boxo - restore explicit Flush: false in addNode and addDir Mkdir calls that was dropped during the MkdirOpts refactor - use %q for hash function error message in getPrefix - switch from boxo fork replace to upstream boxo@98dabcc * fix(config): always build explicit CidBuilder from defaults UnixFSCidBuilder used to return nil when CidVersion and HashFunction matched compile-time defaults, relying on boxo's internal CIDv0/sha2-256 fallback. This will break when DefaultCidVersion changes to 1, because boxo will keep using CIDv0 regardless. - remove early-return short-circuit in UnixFSCidBuilder - add unit tests for explicit and default CidBuilder construction Refs: #4143 * fix(files): reject chcid on MFS root path The MFS root CID format is now always set from Import.CidVersion and Import.HashFunction at startup, so chcid on "/" was silently overridden on every subsequent command or daemon restart. - chcid now requires a path argument and rejects "/" - help text and changelog explain how to change root CID format - sharness tests use Import config + daemon restarts instead of chcid / - added test for chcid on subdirectories with blake2b-256 * chore(deps): update boxo to latest main Picks up ipfs/boxo#1131: fix concurrent flush/close panic in MFS file descriptors (FUSE race condition). * fix(test): sharness daemon pairing and stale shard hash - add restart_daemon helper to avoid tripping t0015 meta-test that counts literal test_kill/test_launch pairs in each file - update cidv1 SHARD_HASH to match current boxo HAMT output --------- Co-authored-by: Andrew Gillis <11790789+gammazero@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a FUSE panic found in Kubo when running FUSE tests on CI (log).
When the FUSE kernel dispatches
FLUSHandRELEASEconcurrently for the same file handle, bothFlushandClosecall intoflushUp, which accesses the underlyingDagModifierwithout synchronization. Two concurrentSynccalls race on the write buffer, causing a nil pointer dereference.This PR adds a mutex to
fileDescriptorthat serializesFlushandClose, and returnsErrClosedwhenFlushis called afterClose.Also adds
Directory.Mode()andDirectory.ModTime()read-only getters to match the existingFileAPI, needed by the Kubo FUSE layer.Changes
mfs/fd.go: addsync.MutextofileDescriptor, acquired inFlushandClosemfs/fd.go:Flushon a closed descriptor now returnsErrClosedmfs/dir.go: addDirectory.Mode()andDirectory.ModTime()gettersmfs/mfs_test.go: addTestConcurrentFlushAndClose(catches regressions with-race)Test plan
TestConcurrentFlushAndClosepasses with-race