IPFS Lock file getting in the way when making multiple calls

Hello, I’ve just started working with js-ipfs and have run into an error surrounding the lock file. I have this function that returns the content of JSON ipfs files, it works fine when I call it once, but when I try to call it twice I get this error:
Lock already being held for file: /Users/jackmanning/.jsipfs/repo.lock
at Object.exports.lock
(/Users/jackmanning/Documents/testDisplay(ILA)/node_modules/ipfs-
repo/src/lock.js:37:13)
at async IpfsRepo._openLock
(/Users/jackmanning/Documents/testDisplay(ILA)/node_modules/ipfs-
repo/src/index.js:199:22)
at async IpfsRepo.open
(/Users/jackmanning/Documents/testDisplay(ILA)/node_modules/ipfs-
repo/src/index.js:113:23)
at async openRepo
(/Users/jackmanning/Documents/testDisplay(ILA)/node_modules/ipfs-
core/src/components/storage.js:88:7)
Here is my code:
async function getAttributes(ipfsLink) {
const node = await IPFS.create()
const stream = node.cat(ipfsLink);

let metadataStr = ''

for await (const chunk of stream) {
    // chunks of data are returned as a Buffer, convert it back to a string
    metadataStr += chunk
}
// gets data as object
const dataObj = JSON.parse(metadataStr);

// gets image, description, and name
const image = dataObj["image"];
const description = dataObj["description"];
const name = dataObj["name"];

// console.log('image: ', image)
// console.log('description: ', description)
// console.log('name: ', name)
const finalProduct = 
    {
        "img": image,
        "title": name,
        "desc": description
    }

//stream.stop();
return finalProduct;
}

Let me know if you have any solutions or if more information would be helpful.
Thanks

I think maybe you just need something like this when you’re done:

await node.stop()
1 Like