Repository navigation
Description
After deploying using firebase-tools 12.6.1, our functions are crashing at runtime with the following stacktrace:
Error: TypeError: Cannot read properties of undefined (reading 'headers')
at /layers/google.nodejs.yarn/yarn_modules/node_modules/firebase-functions/lib/v2/trace.js:12:68
at /layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/function_wrappers.js:141:25
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at console.error (/layers/google.nodejs.yarn/yarn_modules/node_modules/firebase-functions/lib/logger/compat.js:31:23)
at sendCrashResponse (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/logger.js:27:17)
at sendResponse (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:37:40)
at /layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/function_wrappers.js:34:40
at bound (node:domain:433:15)
at runBound (node:domain:444:12)
at /layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/function_wrappers.js:142:60
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
We're also crashing in our own code when trying to read request.rawBody.toString() as rawBody is undefined. It looks like something is wrong with the request objects being passed to the http functions.
We saw a very similar issue in 12.5.0 (#6290)
It looks like with this PR #6376 the issue might have been reintroduced.
@blidd-google can you take a look at this please?
[REQUIRED] Environment info
firebase-functions v2
Node 18.12.1
firebase-tools:
12.6.1
Platform:
[REQUIRED] Test case
Deploy a V2 http function with 12.6.1
Redeploy with 12.4.8 and functions work correctly
[REQUIRED] Steps to reproduce
Deploy a V2 http function with 12.6.1
[REQUIRED] Expected behaviour
It should not crash, correct properties should be defined on the request/response object
[REQUIRED] Actual behaviour
Crash, request object properties are undefined
Activity
google-oss-bot commentedon Sep 28, 2023
This issue does not seem to follow the issue template. Make sure you provide all the required information.
aalej commentedon Sep 28, 2023
Hey @milo-, sorry to hear you’re encountering this issue. I’m currently trying to reproduce the error you mentioned but so far I am unable to replicate this. I tried deploying a mixture of v1 and v2 HTTP functions:
Making a POST request to any of the HTTP functions above does not raise any errors. In case I’m missing anything here, please let me know.
Could you provide additional information here such as if you’re deploying a mixture of v1 and v2 functions or just multiple v2 functions? By any chance, if you can provide a sample code snippet of the function(s) you’re deploying, we would highly appreciate it.
milo- commentedon Sep 28, 2023
Hi @aalej, yep we're deploying ~60 functions, 50/50 mixture of v1 functions and v2 functions.
We were seeing this issue in the following v2 functions:
All these functions are group functions. Ill try and get a smaller repro for you.
lelimit commentedon Sep 28, 2023
I also got problems at runtime after deploying onCall v2 functions with with 12.6.1.
TypeError: res.on is not a function
milo- commentedon Sep 29, 2023
I've been unable to create a small reproduction. But can confirm this issue happens every time we deploy with 12.6.1.
Deploying the individual function fixes the issue, but when all functions are deployed together, the runtime error res.headers is undefined starts getting thrown again.
@blidd-google I've been digging into the source and the logs. Something that seems strange is there's a v1 and a v2 scraper, so I'd expect a source token for v1, source token for v2. However during deployment, it logs 4 different source tokens:
3 x UUID source tokens
1 x 384 character source token
blidd-google commentedon Oct 2, 2023
Hi @milo-, very sorry for all the disruptions you've run into. I'm investigating the issue now and am also having trouble creating a repro of the bug you've described, but I'll keep this thread updated.
blidd-google commentedon Oct 3, 2023
A couple of follow up questions:
onRequestfunction?--debugflag?23 remaining items
lox commentedon Oct 22, 2023
Firebase folks, feel free to book me here for a quick video call to assist with reproducing the issue:
https://zcal.co/lox/firebase-6414
ChromeQ commentedon Oct 22, 2023
I also ran into this since 12.6.0 (and 12.6.1 and 12.7.0)

I can also confirm from my logs that it is calling the incorrect functions after deployment. This is because the incorrect functions are potentially being deployed somehow, I have all v2 functions (3 firestore documents handlers + 2 scheduled functions) and I can see the following in the logs when deploying:
It shows the incorrect function was (potentially?) deployed, in this case "towntime" is the name of a new scheduled function added - this can be seen more clearly when searching for "Default STARTUP TCP probe succeeded after 1 attempt for container" and it deployed and worked correctly until the 20th October (when I upgraded)

Happy to get on that call with you I just booked using your link @loxlox commentedon Oct 22, 2023
@ChromeQ I am experiencing the issue myself, not a Firebase dev 😅
blidd-google commentedon Oct 23, 2023
Hi all, we've been able to reproduce the error and have identified the underlying bug. We're currently working on a fix and will keep folks updated on this issue thread. Thanks for your continued patience as we iron out the remaining kinks with the single builds feature - we believe that the improvements in deploy speed & reliability that single builds offer are worth the effort, and you should be able to take advantage of those improvements without problems very soon!
lox commentedon Oct 27, 2023
@blidd-google are you able to address these questions:
My confidence in Firebase Functions is at an all time low after this issue and the recent multi-hour deployment outage that didn't even merit a status page update.
Would really help to see a nuanced response here, are there any product managers involved in Firebase any more or is it more best-effort internally?
joehan commentedon Oct 31, 2023
First off, a quick update: We have a backend fix for this issue rolling out to production. It should land this week.
To answer @lox 's questions:
Did this affect all V2 functions? What was the identified issue?Though there were a couple issues related to this launch, this specific issue only affected deployments with multiple V2 functions using different trigger types.
A brief bit of background: previously, deployments of many functions would generate some nearly identical artifacts for each function. This update used 'source tokens' to tell Cloud Functions to reuse these artifacts where possible to make deploys faster, cheaper, and more reliable.
The cause of this issue is a bug where functions deployed with a source token used the trigger type of the function that created that source token instead of the correct trigger type. This trigger type controls how the Cloud Function decodes requests and responses. So, for example, if a source token from a Firestore triggered function was used for a HTTPS function, it would error out when trying to decode a HTTPS request as a request from Firestore.
If functions were being incorrectly invoked, could there have been security impact? For instance onDocumentUpdate functions triggered by http without auth checks?This issue did not have any security impact. The correct functions are being called, this was just causing errors with how requests were decoded.
Why was a change of this magnitude introduced in a minor version? Will the release regime in future change?We added this in a minor version because it is not an 'incompatible API change', per https://semver.org/.
We do understand the frustration here, and we definitely need to do a better job of catching issues like this before they reach you. This issue exposed some gaps in our test coverage, and we're currently working on a revamp the functions integration test suite. Additionally, while Github is a great place to report issues, please reach out to Firebase Support for help with any billing issues.
lox commentedon Oct 31, 2023
Thanks for the detailed update @joehan!
Very much looking forward to being able to benefit from artifact re-use (and speed up our deploys).
ChromeQ commentedon Nov 2, 2023
Thanks for the update @joehan , I gave this a try and it seemed to work for the most part (although I only deployed two functions of the same type so may not have been a problem as per your description above)
However there is an issue within the logs which gave me the impression it was not resolved:
Ignore the error (that was me prematurely deleting a storage bucket!) but you can see the bit above saying the function named "scrape-happiest-hour" was deployed and successfully probed the container, this was using [email protected].
After the upgrade to [email protected] this morning and another deploy at 10.36am - you can see the probe on the container named "scrape-towntime" (the other function I deployed at the same time as this one).
But the next lines are the invocation of the function and the correct name comes through "scrape-happiest-hour" - so it seems it is working correctly.
But as I mentioned the container name is incorrect and mixed up with the first named function, this is the command I ran:
firebase deploy --only functions:scrapeTowntime,functions:scrapeHappiestHourso it looks like the first function listed is the name coming through all the others as described in your analysis earlier.Hope this helps track down any other lingering problem that may still exist.
wokkaflokka commentedon Nov 2, 2023
@joehan thank you for the clear explanation -- very well done.
@ChromeQ -- If i take the explanation from @joehan, they've stated "We have a backend fix for this issue rolling out to production. It should land this week."
Based on that comment, it's not clear that the proposed fix has been released. The name mismatch is characteristic of the initial reported error and is more generally characteristic of the class of error as disclosed by maintainers. I hope your issue is fixed and wish I could help more.
lox commentedon Nov 2, 2023
I assume https://github.com/firebase/firebase-tools/releases/tag/v12.8.0 didn't include the fix.
arnoutvandervorst commentedon Nov 2, 2023
Based on that backend fix, any version after 12.5.4 won't work in our cases since that version started using single builds. When the backend fix has been released, we can safely upgrade to any new version.
milo- commentedon Nov 5, 2023
@joehan has the backend fix landed in production? Thanks!
blidd-google commentedon Nov 7, 2023
The backend fix for the single builds feature has been fully released; functions deployed with CLI versions >=12.6.2 will be able to correctly decode requests. We will continue to monitor this thread in case anything else comes up, but thank you all for your patience as we ironed out the kinks for this feature. As @joehan mentioned, the Firebase functions team is working on overhauling our integration tests to mitigate potential future issues as we continue to make improvements to 2nd gen functions.
joehan commentedon Nov 7, 2023
I'm going to close this issue for now since AFAIK, it is fixed. If you've had any issues with your functions, the quickest way to fix them should be to update to the latest version of firebase-tools and redeploy them. Please don't hesitate to ping here again (or open new issues) if you are still having trouble with functions deploy.