Firebase-js-sdk: firebase.loadFirestoreRules timing out in emulator

Created on 22 Nov 2018  ·  6Comments  ·  Source: firebase/firebase-js-sdk

Describe your environment

  • Operating System version: _____Mac
$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.14
BuildVersion:   18A391
$ node --version
v10.13.0
  • Browser version: _____N/A
  • Firebase SDK version: _____
    "@firebase/testing": "^0.3.3",
    "firebase": "^5.5.9",
    "firebase-admin": "^6.2.0",
    "firebase-functions": "^2.1.0",
    "firebase-functions-test": "^0.1.5",
    "firebase-tools": "^6.1.1"

Describe the problem

It appears that successive calls to firebase.loadFirestoreRules are increasingly slower, to the point where it quickly becomes unusable.

This is a regression, though I have not been able to pinpoint where, and might be Mac specific.

Relevant Code:

Minimum working reproduction here: brianmhunt/bug-reports#firestore-emulator-timeouts

Steps to reproduce:

Sample output from the reproduction repo:

  firebase emulator
    ✓ does not time out (101ms)
    ✓ does not time out 2 (968ms)
    ✓ does not time out 3 (1316ms)
    ✓ does not time out 4 (2168ms)
    ✓ does not time out 5 (4717ms)
    ✕ does not time out 6 (5009ms)

  ● firebase emulator › does not time out 6

    Timeout - Async callback was not invoked within the 5000ms
    timeout specified by jest.setTimeout.

    Rules loaded in 21 ms

  console.log test/firebase.test.js:17
    App initialized in 2 ms

  console.log test/firebase.test.js:14
    Rules loaded in 900 ms

  console.log test/firebase.test.js:17
    App initialized in 0 ms

  console.log test/firebase.test.js:14
    Rules loaded in 1603 ms

  console.log test/firebase.test.js:17
    App initialized in 0 ms

  console.log test/firebase.test.js:14
    Rules loaded in 2520 ms

  console.log test/firebase.test.js:17
    App initialized in 0 ms

  console.log test/firebase.test.js:14
    Rules loaded in 4417 ms

  console.log test/firebase.test.js:17
    App initialized in 1 ms

testlab

Most helpful comment

As a workaround, you can set the environment variable FIREBASE_FIRESTORE_EMULATOR_ADDRESS=127.0.0.1:8080 to force the testing SDK to connect via ipv4. That should resolve the timeouts.

All 6 comments

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

Having narrowed down the issue, it can be much simpler to reproduce with:

    await firebase.loadFirestoreRules({ projectId, rules }) // ~20 ms
    await firebase.loadFirestoreRules({ projectId, rules }) // ~900 ms
    await firebase.loadFirestoreRules({ projectId, rules }) // ~1600 ms
    await firebase.loadFirestoreRules({ projectId, rules }) // ~2500 ms
    await firebase.loadFirestoreRules({ projectId, rules }) // ~4400 ms

So the time to load the rules is roughly doubling with every call.

One workaround is to set a very high timeout e.g. in the case of jest jest.setTimeout(50000). This is of course less than ideal.

This is likely the same issue that was fixed for the Firestore SDK in https://github.com/firebase/firebase-js-sdk/pull/1390

I'll do the same thing in the rules loader

As a workaround, you can set the environment variable FIREBASE_FIRESTORE_EMULATOR_ADDRESS=127.0.0.1:8080 to force the testing SDK to connect via ipv4. That should resolve the timeouts.

Thanks for the updates @ryanpbrewster, glad to see this sorted.

Was this page helpful?
0 / 5 - 0 ratings