firebase / firebase-tools

The Firebase Command Line Tools
MIT License
4.02k stars 937 forks source link

Emulator crashes in unexpected state when queried with startAfter(undefined). forced to restart. #3579

Open davidbielik opened 3 years ago

davidbielik commented 3 years ago

I'm running into a bug that puts the emulator into a bad state, causing all subsequent queries to fail, and forces me to restart the emulator.

[REQUIRED] Environment info

firebase-tools: 9.16.0

Platform: macOS

[REQUIRED] Test case

see STR:

[REQUIRED] Steps to reproduce

  1. Add documents to a collection:
await Promise.all([
   firebase.firestore().collection("test").add({"type": "3", created_at: firebase.firestore.FieldValue.serverTimestamp()}),
   firebase.firestore().collection("test").add({"type": "3", created_at: firebase.firestore.FieldValue.serverTimestamp()}),
]);
  1. Confirm you can query successfully with no errors:
(await firebase.firestore().collection('test')
    .limit(5)
    .where("type", "==", "3")
     .orderBy("created_at", "desc")
     .get()
).docs.map(d => d.data())
  1. Add in startAfter(undefined) to the query:
    (await firebase.firestore().collection('test')
    .limit(5)
    .where("type", "==", "3")
     .orderBy("created_at", "desc")
     .startAfter(undefined) // <---- causes the error
     .get()
    ).docs.map(d => d.data())

    [REQUIRED] Expected behavior

The parameter should be skipped, or worst case an error message around not being able to pass undefined

[REQUIRED] Actual behavior

[2021-07-14T21:29:17.408Z]  @firebase/firestore: Firestore (8.6.8): INTERNAL UNHANDLED ERROR:  TypeError: Cannot use 'in' operator to search for 'nullValue' in null
Uncaught (in promise) TypeError: Cannot use 'in' operator to search for 'nullValue' in null
[2021-07-14T21:29:44.986Z]  @firebase/firestore: Firestore (8.6.8): FIRESTORE (8.6.8) INTERNAL ASSERTION FAILED: Unexpected state
Uncaught Error: FIRESTORE (8.6.8) INTERNAL ASSERTION FAILED: Unexpected state

Here's a screenshot showing the same steps in my local console:

image

google-oss-bot commented 3 years ago

This issue does not have all the information required by the template. Looks like you forgot to fill out some sections. Please update the issue with more information.

boweiliu commented 1 year ago

I was having this issue as well. For anyone else debugging, this seemed to happen not only on the emulator, but on QA firebase as well. The root cause for us seemed to be calling .get() on the firestore object before the websocket was fully initialized.

The firestore logs were very unhelpful in debugging this issue:

Uncaught (in promise) TypeError: Cannot use 'in' operator to search for 'nullValue' in null
    at vt (prebuilt-2d830653-6eee25bb.js?635b:1199:1)
    at yt (prebuilt-2d830653-6eee25bb.js?635b:1195:1)
    at eval (prebuilt-2d830653-6eee25bb.js?635b:1581:1)
    at eval (prebuilt-2d830653-6eee25bb.js?635b:1582:14)
    at Array.map (<anonymous>)
    at kt (prebuilt-2d830653-6eee25bb.js?635b:1576:1)
    at oe (prebuilt-2d830653-6eee25bb.js?635b:1913:1)
    at t.eval [as mapKeyFn] (prebuilt-2d830653-6eee25bb.js?635b:11673:1)
    at t.get (prebuilt-2d830653-6eee25bb.js?635b:6766:1)
    at eval (prebuilt-2d830653-6eee25bb.js?635b:11702:1)
    at step (tslib.es6.js?f7a0:102:1)
    at Object.eval [as next] (tslib.es6.js?f7a0:83:46)
    at eval (tslib.es6.js?f7a0:76:1)
    at new Promise (<anonymous>)
    at __awaiter (tslib.es6.js?f7a0:72:1)
    at vs (prebuilt-2d830653-6eee25bb.js?635b:11697:13)
    at n (prebuilt-2d830653-6eee25bb.js?635b:14469:1)
    at eval (prebuilt-2d830653-6eee25bb.js?635b:14473:1)
    at step (tslib.es6.js?f7a0:102:1)
    at Object.eval [as next] (tslib.es6.js?f7a0:83:46)
    at fulfilled (tslib.es6.js?f7a0:73:43)

[2023-04-14T23:17:11.215Z]  @firebase/firestore: Firestore (8.10.1): FIRESTORE (8.10.1) INTERNAL ASSERTION FAILED: Unexpected state
joehan commented 1 year ago

Looks like this is actually an issue with @firebase/firestore. Will get this moved over to the right repo to get this in front of people who can fix it.