There's a document in my firebase collection which I am not able to delete either through the admin SDK or through the firestore ui. Through the firestore UI it just keeps on loading. It happens only for this specific document as it went through some failed transaction state a while ago.
Document path -
mohallas/Ax7nRPPighhHXoO4THIRxmVjsAk2
I can delete the field of the document but somehow it manages to get back those fields. It's a strange thing. In my opinion, it looks like a deadlock state.
If I try to clear the fields of the document the client sdk still has an old copy of this document somehow.
The logs of the firebase cloud function which has a transaction to update the document are as such
Code for the cloud function
exports.inRoomUsersCounter = functions.runWith({ timeoutSeconds: 540 }).firestore.document('/in_room_users/{doc}').onWrite(async (change, context) => {
let mohallas = "mohallas"
let homes = "rooms"
let eventId = context.eventId;
if (change.before.exists && change.after.exists && change.before.get('mohalla') === change.after.get('mohalla') && change.after.get('home') === change.before.get('home')) {
return null;
}
let d = await getFunctionEvent(eventId);
if (d.exists()) {
return null;
}
await memoizeFunctionEvent(eventId);
if (change.before.exists && change.after.exists) {
let changeBeforeData = change.before.data();
let changeAfterData = change.after.data();
await db.runTransaction(async (t) => {
t.update(db.collection(mohallas).doc(changeBeforeData.mohalla), { 'count': FieldValue.increment(-1) });
t.update(db.collection(mohallas).doc(changeBeforeData.mohalla).collection(homes).doc(changeBeforeData.home), { 'count': FieldValue.increment(-1) });
}, { maxAttempts: 30 });
await db.runTransaction(async (t) => {
t.update(db.collection(mohallas).doc(changeAfterData.mohalla), { 'count': FieldValue.increment(1) })
t.update(db.collection(mohallas).doc(changeAfterData.mohalla).collection(homes).doc(changeAfterData.home), { 'count': FieldValue.increment(1) })
}, { maxAttempts: 30 });
return Promise.resolve();
}
else if (!(change.before.exists) && change.after.exists) {
let changeAfterData = change.after.data();
return db.runTransaction(async (t) => {
t.update(db.collection(mohallas).doc(changeAfterData.mohalla), { 'count': FieldValue.increment(1) })
t.update(db.collection(mohallas).doc(changeAfterData.mohalla).collection(homes).doc(changeAfterData.home), { 'count': FieldValue.increment(1) })
}, { maxAttempts: 30 });
}
else if (change.before.exists && !(change.after.exists)) {
let changeBeforeData = change.before.data();
return db.runTransaction(async (t) => {
t.update(db.collection(mohallas).doc(changeBeforeData.mohalla), { 'count': FieldValue.increment(-1) })
t.update(db.collection(mohallas).doc(changeBeforeData.mohalla).collection(homes).doc(changeBeforeData.home), { 'count': FieldValue.increment(-1) })
// return Promise.resolve();
}, { maxAttempts: 30 })
}
return Promise.resolve();
})

