Freeze while trying cat

Hi guys. I’m newbie in IPFS.

I’m trying to cat this file: ipn:QmQUXM5vQKBf715uzLYwK5tfo5RigvVerEYuoFdmNN3Fu1 but all methods ends in a freeze call.

by console:

ipfs cat QmQUXM5vQKBf715uzLYwK5tfo5RigvVerEYuoFdmNN3Fu1

by explorer:

By ipfs api: https://ipfs.io/ipfs/QmQUXM5vQKBf715uzLYwK5tfo5RigvVerEYuoFdmNN3Fu1

Can someone helpme to understand wath happends??

1 Like

Hi. Did you ever get to the bottom of this issue?

I am experiencing the same with your file … but found this post because I have the same issue with something kinda silly and definitely unexpected, which might help explain what was happening for you, though it’s not going to help.

If I create a file with contents …

contents = "Hello World 101"

… then I can ipfs cat the resulting CID as expected.

However, if I add a file containing …

contents = "Hello World 101\n"

… then I experience the freeze, just like you.

The simple addition of a newline character \n somehow causes a problem.

ipfs version 0.24.0 running on Ubuntu 22.04.3 LTS

More specifically …

/* eslint-disable no-console */

// this file is regular CommonJS

async function main () {
  const { createHelia } = await import('helia')
  const { unixfs } = await import('@helia/unixfs')

  // create a Helia node
  const helia = await createHelia()

  // print out our node's PeerId
  console.log(helia.libp2p.peerId)

  // create a filesystem on top of Helia, in this case it's UnixFS
  const fs = unixfs(helia)

  // we will use this TextEncoder to turn strings into Uint8Arrays
  const encoder = new TextEncoder()

  // add the bytes to your node and receive a unique content identifier
  const cid = await fs.addBytes(encoder.encode("Hello World 101\n"), helia.blockstore)

  console.log('Added file:', cid.toString())

  // this decoder will turn Uint8Arrays into strings
  const decoder = new TextDecoder()
  let text = ''

  for await (const chunk of fs.cat(cid)) {
    text += decoder.decode(chunk, {
      stream: true
    })
  }

  console.log('Added file contents:', text)
}

main().catch(err => {
  console.error(err)
  process.exit(1)
})
node indes.js
PeerId(12D3KooWQpZBeTmQ2VGZMBQkPX8bho8XiZ8rvoVZCYvqM71X49uR)
Added file: bafkreifjmburyvq23vcjz2vx4tpfu6zaogqe6fixzcrh2zqbnljzdg7zee
Added file contents: Hello World 101

^C
$ ipfs cat bafkreifjmburyvq23vcjz2vx4tpfu6zaogqe6fixzcrh2zqbnljzdg7zee
< freezes here, never to return to shell prompt >

If I remove the \n then everything if fine …

node index.js
PeerId(12D3KooWHQDVUpSVQiEKx9pCiphcVqNJcGwhWDbYbFQthqEHbSVS)
Added file: bafkreife2klsil6kaxqhvmhgldpsvk5yutzm4i5bgjoq6fydefwtihnesa
Added file contents: Hello World 101
^C
$ ipfs cat bafkreife2klsil6kaxqhvmhgldpsvk5yutzm4i5bgjoq6fydefwtihnesa
Hello World 101

Your issue is unrelated to the post above.

It seems you are adding something to Helia and reading it with Kubo. What you added is not stored in the same place, so Kubo will try to fetch it from the network. I don’t know if something needs to be done in Helia for that to happen, certainly a helia daemon should run or something so that it can serve the content.

The fact that it works with the first form of the content probably means that you added this content to Kubo already and it is present locally. I suspect if you change content to something completely different, it will hang in all cases?

Oh? I thought Helia and Kubo were both general IPFS clients, both accessing the actual IPFS network. :confused:

Seems you’re right. Someone else must have written that string to the ‘actual’ IPFS and I can only guess that identical data ends up getting the same CID every time or something.

Thanks for the assist! Dig deeper I will.

That’s correct. But they need to be connected to the network to serve content requested by other peers at the moment when it is requested. It is not uploaded anywhere when added to Helia.

That’s the whole precept of IPFS.