I have a Firebase cloud function that is loosely based on this example https://github.com/firebase/functions-samples/tree/master/image-sharp
Today, when deploying some small changes it gave me this warning
$ firebase deploy --only functions
⚠ functions: package.json indicates an outdated version of firebase-functions.
Please upgrade using npm install --save firebase-functions@latest in your functions directory.
so I did the upgrade, which upgraded firebase-functions from ^1.0.3 to ^2.0.0
since then have been getting this when running the function
Function execution took 60002 ms, finished with status: 'timeout'
instead of the usual
Function execution took 10 ms, finished with status: 'ok'
I started stripping down my function but even going down to bare bones it was still getting the error.
I then started a new project used the example function as is and it behaves exactly the same way. With firebase-functions ^2.0.0 it gives the timeout error but with ^1.0.0 it works fine.
Is this a known issue?
Thanks
Here is the example code
exports.generateThumbnail = functions.storage.object().onFinalize((object) => {
const fileBucket = object.bucket; // The Storage bucket that contains the file.
const filePath = object.name; // File path in the bucket.
const contentType = object.contentType; // File content type.
// Exit if this is triggered on a file that is not an image.
if (!contentType.startsWith('image/')) {
console.log('This is not an image.');
return null;
}
// Get the file name.
const fileName = path.basename(filePath);
// Exit if the image is already a thumbnail.
if (fileName.startsWith('thumb_')) {
console.log('Already a Thumbnail.');
return null;
}
// Download file from bucket.
const bucket = gcs.bucket(fileBucket);
const metadata = {
contentType: contentType,
};
// We add a 'thumb_' prefix to thumbnails file name. That's where we'll upload the thumbnail.
const thumbFileName = `thumb_${fileName}`;
const thumbFilePath = path.join(path.dirname(filePath), thumbFileName);
// Create write stream for uploading thumbnail
const thumbnailUploadStream = bucket.file(thumbFilePath).createWriteStream({metadata});
// Create Sharp pipeline for resizing the image and use pipe to read from bucket read stream
const pipeline = sharp();
pipeline
.resize(THUMB_MAX_WIDTH, THUMB_MAX_HEIGHT)
.max()
.pipe(thumbnailUploadStream);
bucket.file(filePath).createReadStream().pipe(pipeline);
const streamAsPromise = new Promise((resolve, reject) =>
thumbnailUploadStream.on('finish', resolve).on('error', reject));
return streamAsPromise.then(() => {
console.log('Thumbnail created successfully');
return null;
});
I was going to comment but it requires me 50+ reputations.....
Anyway, I am experiencing the same problem:
exports.sendNotificationForMessage = functions.firestore.document('chatrooms/{chatroomId}/messages/{messageId}').onCreate((snap, context) => {
const newMessage = snap.data();
const messageContent = newMessage.text;
const senderName = newMessage.senderDisplayName;
const senderId = newMessage.senderId;
const chatroomId = context.params.chatroomId;
console.log(newMessage)
return true;
});
It finished with status timeout.
If it's a problem with firebase-function 2.0, what is the command to downgrade it back to version 1.x? Googled about it but no luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With