Skip to content

Firestore emulator calls functions twice on startup #8774

Open
@ryanadrig

Description

@ryanadrig

[REQUIRED] Environment info

firebase-tools: 14.6.0

Platform: Ubuntu 24.10

[REQUIRED] Test case

Create a python functions instance with initialize_app() and db = firestore.client(). Create a function that inserts 100 documents in a while loop (also works with batched write) inserting with db.collection("collection_name").document().set(<doc>) start emulator with firebase emulators:start

[REQUIRED] Steps to reproduce

Run endpoint with curl or API testing tool (I'm using insomnia).

[REQUIRED] Expected behavior

Expect inserts to be called once

[REQUIRED] Actual behavior

Function is run twice, inserting documents twice. When the function runs twice, I see Jun 18, 2025 9:03:27 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead INFO: Detected HTTP/2 connection. in firestore-debug.log. I see this when running other functions for the first time, including read all with fdb.collection("collection_name").stream() and always get the channelRead log when runs twice, but after running it again it runs once as expected with no log.

I've seen these articles https://firebase.google.com/docs/functions/tips https://cloud.google.com/blog/products/serverless/cloud-functions-pro-tips-building-idempotent-functions suggesting idempotency but they imply this is only an issue for triggered background functions which have an eventID, these calls do not have an eventID. This video ( mostly the one before it https://www.youtube.com/watch?v=MzTS6mFDGjU&list=PLl-K7zZEsYLm9A9rcHb1IkyQUu6QwbjdM&t=3m22s just briefly says "background functions") also switches from cloud Functions to triggers/background functions when mentioning there could be duplicate runs https://www.youtube.com/watch?v=Pwsy8XR7HNE&t=12s And anything else I could find blamed CORS which would happen every request not once and stop, and the only http status I see is 200 not 204 like they say for CORS.

So I don't think this should be the behavior

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions