[go: nahoru, domu]

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

Documentation: how many times does my functions code get launched #919

Open
akauppi opened this issue Jul 21, 2021 · 1 comment
Open

Documentation: how many times does my functions code get launched #919

akauppi opened this issue Jul 21, 2021 · 1 comment

Comments

@akauppi
Copy link
akauppi commented Jul 21, 2021

Related issues

[REQUIRED] Version info

node: 16.5

firebase-functions: 3.14.1

firebase-tools: 9.16.0

firebase-admin: 9.11.0

[REQUIRED] Test case

The issue/question is generic in nature, but steps to reproduce are added below. In addition, logs are available in this discussion.

I noticed yesterday that the functions/index.js gets imported three times at the launch of Firebase Emulators, and thought this strange.

Having checked the Getting Started section, I found no mention about this. Not sure if it is a feature of the Firebase Emulators or the Cloud Functions implementation, in general.

Why this matters?

People do initialisation in the module body. If such things are time-taking, it is good to know that the body is called 1 + (number of functions in it) times, at initialisation. If this is intended, I think it should be mentioned in the docs.

The sample code shows initialising admin.initializeApp(); in the module body.

When moving to ES modules, this becomes even more important. EcmaScript modules are intended to be imported only once, and cached, so authors naturally expect such behaviour. I am not asking for change of implementation. I am asking for clarifying these things in the documentation.

[REQUIRED] Steps to reproduce

$ git clone https://github.com/akauppi/GroundLevel-firebase-es.git
$ cd GroundLevel-firebase-es
$ git checkout next
$ npm install
...
$ cd packages/backend
# Edit 'functions/index.js', adding a logging for "__LOADED__" or similar.
$ npm run start

[REQUIRED] Expected behavior

The functions/index.js gets loaded once.

[REQUIRED] Actual behavior

The functions/index.js gets loaded 3 times.

  • first, before the green lines about functions having loaded are shown
  • once for each function included in it

Were you able to successfully deploy your functions?

Yes.

I haven't observed what the behaviour in the cloud is.

@google-oss-bot
Copy link
Collaborator

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

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

No branches or pull requests

3 participants