Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

files.cat function is not executing or logging anything #1013

Closed
ethereumdegen opened this issue Sep 8, 2017 · 6 comments
Closed

files.cat function is not executing or logging anything #1013

ethereumdegen opened this issue Sep 8, 2017 · 6 comments

Comments

@ethereumdegen
Copy link

ethereumdegen commented Sep 8, 2017

When I run this code, the 'WHY ISNT THIS FIRING' never appears in my console. How can that be? No errors appear either. Nothing really it just locks up.



const IPFS = require('ipfs')
const path = require('path')
const os = require('os')
const fs = require('fs')

console.log('ipfs test ')


var mhash = "Qmc5LfkMVAhvzip2u2RjRBRhgVthtSokHsz4Y5bgaBCW2R";


// Create the IPFS node instance
const node = new IPFS()

node.on('ready', () => {

  // Your node is now ready to use \o/


    console.log('NODE READY')
 
 

  // stopping a node
  node.stop(() => {
    // node is now 'offline'
  })
})



node.on('start', () => {

  console.log('NODE START')

  node.files.cat("Qmc5LfkMVAhvzip2u2RjRBRhgVthtSokHsz4Y5bgaBCW2R", function (err, filestream) {
      console.log('err')
      console.log(err)



        console.log('WHY ISNT CAT FIRING ')
      console.log(filestream)

 
  })



})
@daviddias
Copy link
Member

Hi @admazzola. This looks like a bug. A quick way to solve it is just to put the node.files.cat inside the callback for .on('ready'). Seems that bitswap is dropping requests before the node is online.

Let me know if this works.

@ethereumdegen
Copy link
Author

Thanks for looking at this ! Yeah it seems like a bug I cant figure it out. I tried using the .on(ready) callback and it still doesnt work. Any other possibilities ? Could it be my environment?



const IPFS = require('ipfs')
const path = require('path')
const os = require('os')
const fs = require('fs')

console.log('ipfs test ')


var mhash = "Qmc5LfkMVAhvzip2u2RjRBRhgVthtSokHsz4Y5bgaBCW2R";


// Create the IPFS node instance
const node = new IPFS()

node.on('ready', () => {

  // Your node is now ready to use \o/


    console.log('NODE READY')
   node.files.cat("Qmc5LfkMVAhvzip2u2RjRBRhgVthtSokHsz4Y5bgaBCW2R", function (err, filestream) {
      console.log('err')
      console.log(err)

        console.log('WHY ISNT CAT FIRING ')
      console.log(filestream)

 
  })

 

  // stopping a node
  node.stop(() => {
    // node is now 'offline'
  })
})



node.on('start', () => {

  console.log('NODE START')




})

@daviddias
Copy link
Member

Which version are you using? I believe you are hitting #959 (comment) which should be fixed by default on the latest js-ipfs version

I just tried running your code locally and worked for me

@ethereumdegen
Copy link
Author

Thanks for the help! Well I did get this working. It seems like I had used 'ipfs daemon' to upload my file and it wasnt synchroning with my javascript instance of IPFS so that instance didn't have the file. Oddly enough, it did not throw an error it just froze up and never did anything. Does the 'cat' function just freeze up if it can't find the file with that multihash on the network ? If so it seems like it would be nice to have a way to trigger a callback or error when it cannot find the file.

@daviddias
Copy link
Member

Awesome @admazzola!

re: timeouts. Yes, that is one of the things we still have open for discussion, we definitely want to have it, just want to make sure to do it right as we don't have context like in go -> https://github.com/ipfs/interface-ipfs-core/issues/58

@daviddias
Copy link
Member

Closing this issue as the problem was solved. Continue the timeout convo here https://github.com/ipfs/interface-ipfs-core/issues/58

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants