IPFS nodejs sdk hangs when trying to fetch non existing hash

When I try to fetch a non existing hash, the sdk hangs.

Here’s what my code looks like:

const ipfsAPI = require('ipfs-api');
const api = ipfsAPI('/ip4/');

When I try to fetch a valid address using the below code works fine:

    .then(response => console.log('File retrieved:', response))
    .catch(error => console.log('Error while retrieveing file:', error));

But when I try to fetch a non existing address, It hangs and doesn’t stop.

    .then(response => console.log(response))
    .catch(err => console.log(err));

I know that the Go-IPFS HTTP gateway has a timeout of 1h for gettingfiles. It can well be that the HTTP API (which is used by the ipfs-api) has the same timeout. After that you would get the error. So the workaround is to abort the operation yourself if it takes too long.

I just tried it locally, it already hangs >1h. @rohitkhatri would you please open a bug at https://github.com/ipfs/go-ipfs ?

I have opened but at github here’s the url: https://github.com/ipfs/go-ipfs/issues/5537

1 Like