Skip to content

Conversation

@ljluestc
Copy link

Fix: Gracefully Skip Socket Files in ipfs add

Context

When running ipfs add on a directory that contains socket files, the operation fails with a misleading error: use of closed network connection. This breaks bulk add operations if a socket file is accidentally included (e.g., in a development directory) and prevents users from adding the rest of their files.

Goal

The objective is to silently ignore unrecognized file types (specifically socket files) during the ipfs add process. This ensures that ipfs add behaves robustly, similar to how it handles other non-supported file types, and allows the operation to proceed for all valid files.

Implementation Details

client/rpc/unixfs.go

We implemented a wrapper around the standard file directory iterator to catch and handle specific errors.

  • skippingDirectory: A lightweight wrapper around files.Directory that acts as a factory for our custom iterator.
  • skippingIterator: The core logic resides here. It wraps the underlying DirIterator.
    • Error Interception: In Next(), if the underlying iterator returns an error containing "unrecognized file type", we trap it.
    • Skip Logic: Instead of propagating the error, we recursively call Next() again to advance to the next file.
    • Stagnation Detection: To prevent infinite loops (in case the iterator doesn't advance past the error), we track the last error. If we see the exact same error twice in a row without a successful advance, we break the loop.

client/rpc/unixfs_test.go

Added a new test file to verify this behavior isolation.

  • TestSkippingIterator: Creates a temporary directory with a regular file and a unix socket. Verifies that iterating over this directory returns the regular file and checks that no error is returned for the socket.
  • TestSkippingIterator_WithMultiFileReader: Tests the integration with MultiFileReader, which is the component used by the actual ipfs add command, ensuring the fix works in the real pipeline.

Verification

Automated Tests

Run the new verification tests:

go test -v ./client/rpc -run TestSkippingIterator

Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

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

Thanks for looking into this. The error handling approach here works, but it's a workaround at the client/rpc layer rather than fixing the issue at the source.

This means it does not fix cases where one performs import directly via ipfs add without running daemon (no RPC, direct repo access).

The "unrecognized file type" error originates in boxo's files/serialfile.go. A cleaner fix would be adding an option to SerialFileOptions to skip unsupported file types, similar to how DereferenceSymlinks works.

There's ongoing work for IPIP-499 that adds SerialFileOptions wiring through the stack:

Once those PRs land, adding socket/device skipping becomes straightforward:

  1. Add IgnoreUnsupported bool to SerialFileOptions in boxo
  2. Return nil, nil instead of error when the option is set
  3. Update iterator to skip nil nodes
  4. Add --ignore-unsupported flag (name TBD, ideas welcome) in go-ipfs-cmds

This would fix the issue for all consumers (CLI, library, RPC) rather than just client/rpc, and avoids string-matching on error messages.

I'd suggest parking this PR until the IPIP-499 PRs merge, then we can add IgnoreUnsupported using the same pattern. Happy to help with that once the foundation is in place.

@lidel lidel added the status/blocked Unable to be worked further until needs are met label Jan 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/blocked Unable to be worked further until needs are met

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants