firebase / firebase/firebase-js-sdk

Strong consistency is not guaranteed

Open
#5,895 2 comments 0 reactions 0 assignees View on GitHub
api: firestore needs-attention question
Dominant language
TypeScript
Stars
5.1k
Forks
1k
Avg merge
2d 21h
Merged PRs (30d)
37

Description

### [REQUIRED] Describe your environment

* Operating System version: WSL Ubuntu 20.04 on Windows 20H2
* Browser version: Chrome 97.0.4692.71
* Firebase SDK version: master branch (4bd3a888353c26854142b1861f12e0222151af96)
* Firebase Product: firestore

### [REQUIRED] Describe the problem
When I call DocumentReference.get() asynchronously, update the document synchronously, and then do DocumentReference.get() again, I expect to get the last updated document, however, sometimes the old data may be retrieved. (See the code below.)

DocumentReference.get() looks like it's internally treating the request as a query and passing it to the EventManager, but
EventManagerImpl manages the same query in one place, so this probably causes the new request to be lumped in with the old one.

https://github.com/firebase/firebase-js-sdk/blob/4bd3a888353c26854142b1861f12e0222151af96/packages/firestore/src/core/event_manager.ts#L64

#### Steps to reproduce:

The code below (Occasional failures)

#### Relevant Code:
```typescript
it('get document while online with default get options keep strong consistency', () => {
const initialData = { key: 'initial' };
const updatedData = { key: 'updated' };
return withTestDocAndInitialData(persistence, initialData, async docRef => {
// 1. async get
void getDoc(docRef);

// 2. sync update (Or the same with calling functions that update data)
await updateDoc(docRef, updatedData);

// 3. get
// Maybe if request 1 is resolved late, the same data as request 1 will be returned
// I think this behavior is breaking strong consistency.
const dataGotAfterUpdate = await getDoc(docRef);

expect(dataGotAfterUpdate.data()).to.deep.equal(updatedData);
});
});
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.