Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

functions emulator crashes when accessing config in global space #4158

Closed
danbraik opened this issue Feb 12, 2022 · 13 comments
Closed

functions emulator crashes when accessing config in global space #4158

danbraik opened this issue Feb 12, 2022 · 13 comments
Assignees

Comments

@danbraik
Copy link

[REQUIRED] Environment info

**firebase-tools:**10.2.0

**Platform:**Debian

[REQUIRED] Test case

initialise a project with functions emulator

functions/src/index.ts
import * as functions from "firebase-functions"; const a = functions.config().stripe.stripe_secret_key;

add .runtimeconfig.json
{ "stripe": { "stripe_secret_key": "hello" } }

[REQUIRED] Steps to reproduce

$ npm run build
$ firebase emulators:start --only functions

[REQUIRED] Expected behavior

I expect the emulator to be launched, as in previous version ( <= 10.1.5)

[REQUIRED] Actual behavior

There is an error for accessing config during global space initialisation (it works when it is called later)

`
Error: Error occurred while parsing your function triggers.

TypeError: Cannot read property 'stripe_secret_key' of undefined
at Object. (.../functions/lib/functions/src/index.js:16:36)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at loadModule (.../.npm-global/lib/node_modules/firebase-tools/lib/deploy/functions/runtimes/node/triggerParser.js:10:16)
at .../.npm-global/lib/node_modules/firebase-tools/lib/deploy/functions/runtimes/node/triggerParser.js:34:21
at Object. (...npm-global/lib/node_modules/firebase-tools/lib/deploy/functions/runtimes/node/triggerParser.js:72:3)

`

@danbraik danbraik added the bug label Feb 12, 2022
@spicemix
Copy link

I would like to mention that 10.2 emulator functions broke entirely for me, though they load fine, and I don't notice anything unusual in the logs, other than my functions no longer work. Some of the functions do launch and complete once, but not repeatedly, as I'm using a lot of pubsub cron tasks, also database triggers, etc.

10.1.5 works perfectly, as does the most recent 9.x, and I'm up to date on all other dependencies. I see no errors anywhere, but functions tend to hang, and I have a long wait for them to timeout or I just force kill them along with all the emulators.

I compared what got changed in 10.2 from 10.1.5 and there's too much there for me to have insights without any feedback in the logs. A better series of test cases, exercising the whole API as I'm doing, seems needed to avoid such buggy releases. Thanks for all your work on this!

@eriklundstrom
Copy link

@danbraik I've think I had the same problem. The solution for me was to move the .runtimeconfig.json from the functions folder to the root folder, where my npm script was being called.

@spicemix
Copy link

@eriklundstrom That may make sense since 10.2 uses the env.local approach to setting config information...but it didn't solve my problem.

Further investigations show that the emulator now "sleeps" perhaps like Cloud Functions do, and my workaround to the still-vexing #2034 with SetInterval calls isn't enough to "wake up" the functions I'm calling, and perhaps the same issue results in deadlocks and hung functions as I continue to see in 10.2. Perhaps I would also see these problems on the server (I have never tested on a real firebase server bion, I'm just working in the emulators) but on the real server #2034 wouldn't be a problem either. That bug has been left alive far, far too long, and it may be sticking me and anyone else scheduling functions on the emulators back on 10.1.5 for now.

@charlesfries
Copy link

@eriklundstrom that doesn't fix it for me, the functions build with that change but if you then call them you'll see the same errors.

@taeold
Copy link
Contributor

taeold commented Feb 14, 2022

Hey folks thanks for reporting the issue and chiming in.

Looks like one obvious bug is that functions config are no longer loaded when trying to parse function triggers defined in the source.

@spicemix Your reported issue is alarming. Could you help us out by filing another bug w/ a small reproducible issue if you have time?

@antoniooi
Copy link

Greatly appreciated if the fix can be expedited as our work has been stopped for more than 3 days. Our code depends too much on the cloud functions environment variables for our email notifications to be sent programmatically through the OAuth2 credentials stored in it. We're unable to do the testing and debugging for the new features of our app to be rolled out on time.

If this is gonna take time, is there a way to safely rollback to the earlier working version so that we can continue our work while waiting for the fix to be available? Please advise, thank you so much!

@spicemix
Copy link

@antoniooi

If this is gonna take time, is there a way to safely rollback to the earlier working version so that we can continue our work while waiting for the fix to be available? Please advise, thank you so much!

% npm i -g firebase-tools@10.1.5

If that turns out somehow "unsafe" for you, this will get you back to where we are now:

% npm i -g firebase-tools

@spicemix
Copy link

spicemix commented Feb 15, 2022

@taeold I think the repro for me would just be scheduled functions in the emulator as in #2034 The workaround I'm using is based upon SetInterval(). It may be that 10.2 emulator goes to sleep instead of respecting the SetInterval workaround? I noticed someone has used a workaround in the past using a wget loop in the shell rather than an internal SetInterval which might work in 10.2.

But right now I'm not sure 10.2 offers me enough value over 10.1.5 to upgrade until you've got #2034 finally implemented. Maybe 10.2 is a better test for the Cloud version, but without PubSub scheduled functions, it fails to serve as one right from the get-go for me. I don't know why someone there did all that work on a PubSub emulation without finishing the job. Cron tasks are, you know, kinda important for datastore maintenance and such. And PubSub is the official way to run them on Google Cloud. And I want to use the emulator to develop and test them. And I can't.

Update 2/17/22: 10.2.1 does not fix my problem.

@antoniooi
Copy link

@spicemix

% npm i -g firebase-tools@10.1.5

If that turns out somehow "unsafe" for you, this will get you back to where we are now:

% npm i -g firebase-tools

Thank you so much! Do I need to issue this first for a cleaner downgrade? Would that cause any side effect?
npm remove -g firebase-tools
then only:
npm i -g firebase-tools@10.1.5

@taeold
Copy link
Contributor

taeold commented Feb 15, 2022

@antoniooi Generally, you don't need to issue the remove command.

To double check, print the version after you run your command:

firebase --version

taeold added a commit that referenced this issue Feb 15, 2022
…4162)

Addresses #4158.

I've tried to find a way to add a test for this usecase, but there isn't a framework where I can easily hook in a change like this without big investments. I'm leaning towards releasing this bugfix as is, and finding a less urgent time to add regression test.
@antoniooi
Copy link

Ok guys, rolling back to 10.1.5 allows our team to proceed their work, thanks a lot!
npm i -g firebase-tools@10.1.5
Looking forward for the new bug-fixed version to be released. Thanks again!

@taeold taeold self-assigned this Feb 22, 2022
@taeold
Copy link
Contributor

taeold commented Feb 22, 2022

Note that 10.2.1 includes the fix for the reported bug.

I think @spicemix's issue is separate and being reported on different issues (#4189 and #4166).

@taeold taeold closed this as completed Feb 22, 2022
@rcb4t2
Copy link

rcb4t2 commented Mar 8, 2022

@taeold I'm having rules issues with the storage emulator on 10.2.2. Rolling back to 10.1.5 fixes it. My issue does not seem to be related to spicemix's issues

In our use case, we have Auth using V9, and storage lib using compat V8. Does the fix on 10.2.1 include fixes for the compat v8 lib?

Upload fails with "not authorized" error as if the rules did not permit the operation

Thanks!

#4268

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants