"use of closed network connection" when `ipfs add -r`

I am trying to recursively add a directory using ipfs add -r.

It calculates and displays 8 CIDs, then it stops with: Error: read tcp 127.0.0.1:57868->127.0.0.1:5001: use of closed network connection

Adding the individual files works flawlessly, though.

What could be the cause?

Hard to say. Theipfs add CLI talks to Kubo (ipfs daemon) over HTTP RPC at 127.0.0.1:5001/api/v0, either your daemon got killed, or something killed that connection.

ipfs CLI will prefer HTTP RPC if ~/.ipfs/api is present (or %IPFS_PATH/api)

If you can’t figure out what kills HTTP connection to local RPC, you could try workaround: stop daemon and run ipfs add in offline mode, which operates on repository directly, and once finished, start demon again.

If you have more information and it looks like a bug, report one at GitHub · Where software is built