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.

[firestore-counter] Counter extension run locally: Transaction to aggregate shards failed. TypeError: Cannot read properties of undefined (reading 'length')

See original GitHub issue

Configuration

  • Extension name: Distributed counter
  • Extension version: 0.2.4 (19 Oct 2021)
  • Configuration values (redact info where appropriate): LOCATION=“europe-west3” INTERNAL_STATE_PATH= “firebase_ext/sharded_counter” SCHEDULE_FREQUENCY= 1

Problem

This is a follow-up bug report to this question

During the Implementation of Distributed-Counter-Extension for local emulator I was able to run the scheduled function (controllerCore();) via the firebase shell and it will only work for the first aggregation. The next one will throw the following error:

Transaction to aggregate shards failed. 
TypeError: Cannot read properties of undefined (reading 'length')\n    at /Users/**/Documents/**/**-Backend/functions/internal/counter/controller.js:118:44\n . 

What I have encountered is, that when removing _firebase_ext_ from the local firestore it will work again for one aggregation again (and the directory will be created again). When running the controllerCore again after the error I will get a timeout warning of my worker function.

functions: Your function timed out after ~60s. To configure this timeout, see
      https://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation.
>  /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:618
>              throw new Error("Function timed out.");

Steps to reproduce:

Implement the Counter extension to the local emulator with the following export changes in the index file as described here:

exports.controllerCore = functions.pubsub.schedule(`every ${Config.counter.SCHEDULE_FREQUENCY} minutes`).onRun(async () => {}
exports.worker = functions.firestore.document(`${Config.counter.INTERNAL_STATE_PATH}/workers/{workerId}`).onWrite(async (change, context) => {}
exports.onWrite = functions.firestore.document(`${Config.counter.INTERNAL_STATE_PATH}/workers/{workerId}`).onWrite(async (change, context) => {}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
polarbycommented, Jul 14, 2022

Give me a week for the longest, I will make it sure to notify you about the results.

1reaction
joehancommented, Feb 8, 2022

Wooof, this is a tricky one. Glad to hear that you found a workaround, and AFAIK we’ve never seen this behavior in production. I spent some time digging through the code, and here’s my theory on why you see it only in the emulator:

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read property 'length' of undefined - Firebase
You're missing imports for Firestore (as the error mentions) and Authentication. import * as firebase from "firebase/compat/app"; ...
Read more >
cannot read properties of undefined (reading 'firestore')
firebase/extensionsCounter extension run locally: Transaction to aggregate shards failed. TypeError: Cannot read properties of undefined (reading 'length')# ...
Read more >
Aggregation queries | Firestore - Firebase - Google
This solution offloads the work from the client to a hosted function, which means your mobile app can add ratings without waiting for...
Read more >
Sharded timestamps | Firestore - Google Cloud
On this page · Sharding a timestamp field. Example data model and queries; Adding a shard field; Querying the sharded timestamp; Update index...
Read more >
Aggregation Pipeline and Sharded Collections - MongoDB
When aggregation operations run on multiple shards, the results are routed to the mongos to be merged, except in the following cases: If...
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