Firestore trigger (background function) crashes when uploading youtube video with googleapis
Related issues
[REQUIRED] Version info
node: 10, 12 (tested on both)
firebase-functions: 3.11.0
firebase-tools: 8.10.0
firebase-admin: 9.2.0
[REQUIRED] Test case
I have a firestore trigger that attempts to upload a video using the googleapis (version 61.0.0). Each time the API's video insert is called the firebase function terminates with a 'crash' status. I added log statements both before and after the video insert call to verify it is the insert that crashes.
Note: I created an HTTP callable function with the same logic and that worked leading me to believe it's something to do with background functions. Tested on both a firebase function node 10 & 12 environment.
import { google } from "googleapis";
const bucket_name = '';
const object_name = '';
const client_id = '';
const client_secret = '';
const youtube_oauth_refresh_token = '';
const YOUTUBE_SCOPES = [
'https://www.googleapis.com/auth/youtube.upload',
'https://www.googleapis.com/auth/youtube',
'https://www.googleapis.com/auth/youtube.readonly'
].join(',');
const getYoutubeClient = () => {
const youtubeUploadAuth = new google.auth.OAuth2({
clientId: client_id,
clientSecret: client_secret
});
youtubeUploadAuth.setCredentials({
refresh_token: youtube_oauth_refresh_token,
scope: YOUTUBE_SCOPES
});
youtubeApi = google.youtube({ auth: youtubeUploadAuth, version: 'v3' })
google.options({ auth: youtubeUploadAuth });
return youtubeApi;
}
const youtubeApi = getYoutubeClient();
logger.info('Initialized youtube client'); // this outputs in the console log
const response = await youtubeApi.videos.insert({ // crashes on this line
part: ['snippet', 'status'],
notifySubscribers: false,
requestBody: {
snippet: {
title: 'video title',
description: 'video description',
tags: ['tag 1']
},
status: {
privacyStatus: 'private',
publicStatsViewable: false
}
},
media: {
body: admin.storage().bucket(bucket_name).file(object_name).createReadStream()
}
});
[REQUIRED] Steps to reproduce
- Create a firestore trigger function for a document update (reproducible with onCreate and onWrite) that attempts to upload a video id.
- Trigger the function
[REQUIRED] Expected behavior
The video in the specified bucket path should be uploaded
[REQUIRED] Actual behavior
Function fails with a 'crash' status
Function execution took 4060 ms, finished with status: 'crash'
Were you able to successfully deploy your functions?
Yes, with no errors
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
Hi @agbizzzle. Sorry we are late on responding to this issue.
I can make few guesses on why this might be happening (e.g. background function might be taking up more RAM - try beefing up your function instance?), but can't debug it further without more info. If there are ways for you to share more debug logs (e.g. catch the error that's being thrown), that'd be very helpful.
Let us know!
Marking the issue as closed. Please re-open if you continue have problems.