'Function stops without any logs in firebase (sometimes works well.. sometimes partly) - confused

Can you please share your thoughts or experience why this can happen: I have a folder on firebase cloud with a bunch of images (jpeg, png). It can contain from 2 to 40+ files. After uploading the files from the client is complete, a request is sent to the firebase initiating resizing function of these new images. Resizing should work as:

  • uploading every file to tmpFilePath (for (const file of files) loop is used)
  • resizing the files in tmpFilePath (I tried spawn and sharp, and sharp seems to be more stable)
  • downloading the resized file back to the folder.

The problem is that the function doesn't work from time to time. Sometimes it stops at the step of downloading to tmpFilePath with no logs. After re-initiating, it can proceed a couple of files and stop again. Sometimes it works well. I thought the file size matters, but again, the same folder with the same files can work ok after several initiations.. Confused. Is it specific to firebase functions?

This is a short version of the code:

for (const file of files)  {

console.log(`${file} before downloading to tempFolder`)   


    await destBucket.file(filePath).download({
                destination: tmpFilePath
                })
                .catch((err) => console.log(err))
                .then(() => {

console.log(`${file} before sharp`)

    return sharp (tmpFilePath, { failOnError: false }) 
                      .resize(resizedW, resizedH)
                      .toFile (afterSharpPath) 
                      .then(() => {

console.log(`${file} before uploading back`)  

    return destBucket.upload(afterSharpPath, { 
                    destination: filePath,
                    contentType: orType,
                    metadata: {metadata: newMetadata},
                    bucket: bucket,
                    })
    
    } } }

Anyone have an idea how this can be done?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source