-
Notifications
You must be signed in to change notification settings - Fork 934
runTransaction
isn't awaited
#6915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, Thank you for filling up the ticket! The team is not available for support during the holiday break and we will get back to you in the new year. Happy holiday! |
It may be the |
Hi @cherylEnkidu , were you able to investigate this issue ? |
Hi @pldelattre , I tested the code sample you provide on the production environment but the output is same between |
Interesting. @cherylEnkidu Can you confirm the expected behavior for an awaited transaction is to be awaited until it is commited to the DB ? And that any get call after the awaited transaction should retrieve the updated data and never the data from before the transaction ? |
Hi @Lyokone @pldelattre , In this block of code, I can confirm what you said is expected behaviour. |
Thank you cherylEnkidu. |
I was able to reproduce the similar problem by calling export const app = initializeApp(firebaseConfig, 'app')
export const firestore = initializeFirestore(app, {})
export const app_sub = initializeApp(firebaseConfig, 'app_sub')
export const firestore_sub = initializeFirestore(app_sub, {})
const run = async () => {
const test_doc = doc(firestore, 'tests', 'test')
const test_doc_sub = doc(firestore_sub, 'tests', 'test')
await setDoc(test_doc, { population: 0 })
const unsub = onSnapshot(test_doc, (doc) => {
console.log('Current data: ', doc.data())
})
let newPopulation = 0
for (let i = 0; i < 10; i++) {
newPopulation = newPopulation + 1
console.log('Updating to:', newPopulation)
await updateDoc(test_doc_sub, { population: newPopulation })
const data = await getDoc(test_doc)
console.log('Expected: ', newPopulation)
console.log('Actual: ', data.data()?.population)
console.log('---------')
}
unsub()
}
run() This problem is probably caused by If the above reason is correct, the problem is similar to this one (#5895). In the case of this Issue, it is confirmed that depending on the timing, the problem may occur even if there is no transaction and in the same application. Translated with www.DeepL.com/Translator (free version) |
Hey @Lyokone. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically. If you have more information that will help us get to the bottom of this, just add a comment! |
@pldelattre Did not try @ishowta code, but the result seem to point to an issue in the JS SDK |
I tried with the code @ishowta , unfortunately I still cannot reproduce on my end. |
@cherylEnkidu Here is the code to reproduce in codesandbox https://codesandbox.io/p/sandbox/https-g.yxqyang.asia-firebase-firebase-js-sdk-issues-6915-l2zf6m |
Hi @ishowta , I successfully reproduced the problem use the code you provided. Thank you for spending time! I will take a close look to find out what's going on. |
Hey @Lyokone. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically. If you have more information that will help us get to the bottom of this, just add a comment! |
Hi, Thanks for the all the effort helping us diagnose the issue. The reason why users get mismatch number is because users have When Unfortunately, firestore do not guarantee read-your-own-writes between transaction and non-transaction operations. We do guarantee that within each of those. So if in your case the mismatch is unacceptable, you might need to consider removing |
First reported here: firebase/flutterfire#10153
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
Firestore doesn't retrieve the latest data when using 'getDoc' on a document just after this document was modified through a transaction and a stream to listen on the same document is active.
The content of the retrieved document in the 'getDoc' call should be updated.
This issue is not happening if we are not listening to the document OR if the document is not updated through a transaction.
Steps to reproduce:
It happens on true Firebase instances but is harder to reproduce locally on an emulator.
Relevant Code:
The text was updated successfully, but these errors were encountered: