question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possible regression: Duplicate Firestore trigger event ids

See original GitHub issue

[REQUIRED] Version info

node: v8.11.1

firebase-functions: 2.0.5

firebase-tools: 6.3.0

firebase-admin: 6.0.0

[REQUIRED] Test case

With the following onCreate triggers deployed for the same document:

const functions = require('firebase-functions');
const admin = require('firebase-admin');

exports.functionOne = functions.firestore
  .document('/users/{userId}')
  .onUpdate((snapshot, context) => {
    console.log(context.eventId);
  });

exports.functionTwo = functions.firestore
  .document('/users/{userId}')
  .onUpdate((snapshot, context) => {
    console.log(context.eventId);
  });

[REQUIRED] Steps to reproduce

With the above functions deployed, create a document in the users collection.

[REQUIRED] Expected behavior

The two functions should be called with unique event ids. These should be logged and be different.

[REQUIRED] Actual behavior

The two logged event ids are the same.

Description

I’m not sure if this report belongs in this repo, but using this was where the problem appeared and I wasn’t able to see that the event id comes from elsewhere that I can access.

At some point recently, triggers on the same document like defined above started getting the same event id. Previously if there were multiple triggers for the same document, the event id would have an appended part (like long-uuid-0 and long-uuid-1).

This change caused the code we use to make the functions idempotent to no longer work, and only the first function that reacted to the change was allowed to run.

I haven’t been able to find information about this change anywhere so far, so I’d be curious if there’s anywhere I’ve missed.

Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mbleighcommented, Jan 18, 2019

process.env.FUNCTION_NAME should contain the name of the executing function.

1reaction
inlinedcommented, Jan 18, 2019

Hi Kimroen, the event ID has been a slightly nebulous subject and we’re trying to help add more meaning/standardization to something that was previously not crisply defined.

I completely understand why the event ID alone might be getting used as an idempotency key. I think I myself have recommended the shortcut. The Event ID describes the thing that happened, not the thing that happened + the thing handling it. This means that in the uncommon case where you will have two event handlers talking to the same services (and thus have a potential key collision) you’ll want to add some extra info to your Event ID to make the idempotency key.

This is a bit of extra work for your use case, but seems like the right tradeoff. It’s always possible to rehash something with new info (e.g. creating an idempotency key from event ID + Function) but you can’t undo this operation on an opaque hash. For example, this design is the only way your functions could intentionally coordinate their work so that a 3rd function handles the results of the first two on a per-event basis.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Firestore subcollection [duplicate] - Stack Overflow
First make a reference to the movies collection. Something like this (assuming you have access to your Firestore database):
Read more >
Cloud Firestore triggers | Cloud Functions for Firebase
An update to a Cloud Firestore document, where data is unchanged (a no-op write), will not generate an update or write event. It...
Read more >
Event Sourcing is Hard - Hacker News
I worked on a fairly large system using event sourcing, ... be processed in order based on some ordering key (i.e. time stamp,...
Read more >
Release Notes - Play services - Google Developers
Firebase Android BoM (Bill of Materials); Cloud Firestore ... latest update of the Google Play services TensorFlow Lite library (v16.0.0) is now available....
Read more >
Spring Framework on Google Cloud
All Spring Framework on Google Cloud artifacts are made available through Maven Central. ... to get the Google Cloud project ID and access...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found