RTDB: overlapping writes orphan cancelled transactions and leave subsequent transactions stuck
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- firebase, node.js, typescript
- Domain
- databases
Research direction
Start in repoAbortTransactionsOnNode and trace how SENT_NEEDS_ABORT updates lastSent, then read the datastale response cleanup path. Run the deterministic browser regression cases in ChromeHeadless, including the multi-path and repeated-overlap cases. Done means the cancelled transaction settles, cleanup completes, and subsequent transactions use current server data; the issue notes that a proposed fix and regression tests already exist on another branch.
Written by the indexing model from the issue text.
Description
Operating System
Windows x64 (controlled reproduction); also observed in Linux server applications
Environment (if applicable)
Node.js v24.21.0; Firebase Admin standalone RTDB SDK and the self-contained firebase-database-compat.js browser bundle.
Firebase SDK Version
firebase 12.18.0 (@firebase/database 1.1.5); also firebase-admin 14.3.0 (@firebase/database-compat 2.1.4 / @firebase/database 1.1.3). The same defect is present on main.
Firebase SDK Product(s)
Database
Project Tooling
Minimal Node.js scripts using public SDK APIs, with no framework or network/timing hooks. The proposed PR also includes a deterministic core regression running in ChromeHeadless.
Detailed Problem Description
A transaction cancelled by overlapping writes can be removed from the SDK transaction queue before its outstanding request finishes. If the request then receives datastale, its pending local write is never removed and its completion callback never runs. Subsequent transactions repeatedly receive the same stale input and fail with maxretry, even though updated server data arrives. Reconnecting does not clear the orphaned write; creating a fresh app/database instance does.
In repoAbortTransactionsOnNode, the SENT_NEEDS_ABORT branch does not advance lastSent. A second abort pass therefore leaves lastSent at -1 and clears the transaction tree entry. One update() containing two child paths is enough because repoUpdate invokes transaction cancellation once per path. The datastale response handler searches the transaction tree to finish cleanup, but the removed transaction is no longer reachable.
The fix is lastSent = i for SENT_NEEDS_ABORT, retaining the transaction until its outstanding response can clean it up. Public-API live reproduction: original Admin SDK failed 10/10 multi-path trials; the correction passed all 10, with all single-path controls passing. The exact browser UMD bundle failed 5/5 original trials and passed 5/5 corrected trials.
The proposed fix and regression tests are on https://github.com/pkaminski/firebase-js-sdk/tree/codex/firebase-stuck-sdk. All four deterministic browser regression cases fail on the original source and pass with the correction in ChromeHeadless 156. They cover multi-path and repeated overlapping updates with applyLocally enabled and disabled, completion callbacks, listener cleanup, pending writes and subsequent transaction inputs.
Steps and code to reproduce issue
Run with Application Default Credentials and FIREBASE_DATABASE_URL pointing to a disposable RTDB test instance. This script writes and cleans up only its generated test path.
const {initializeApp, applicationDefault, deleteApp} = require('firebase-admin/app');
const {getDatabase} = require('firebase-admin/database');
const {randomUUID} = require('node:crypto');
async function main() {
const options = {
credential: applicationDefault(),
databaseURL: process.env.FIREBASE_DATABASE_URL
};
const writer = initializeApp(options, 'writer');
const victim = initializeApp(options, 'victim');
const path = 'transaction-cancel-repro/' + randomUUID();
const source = getDatabase(writer).ref(path);
const target = getDatabase(victim).ref(path);
try {
await source.set({version: 0});
let firstSettled = false;
void target.transaction(value => value, undefined, false).then(
() => { firstSettled = true; },
() => { firstSettled = true; }
);
await target.update({'events/a': 1, 'events/b': 2});
try {
await target.transaction(value => value, undefined, false);
} catch (error) {
console.log(error.message); // maxretry
}
console.log({firstSettled}); // false
console.log((await source.get()).val()); // correct server data still exists
} finally {
await source.remove();
await Promise.all([deleteApp(writer), deleteApp(victim)]);
}
}
main().catch(console.error);
Expected: the cancelled transaction settles, and the next transaction uses current server data and completes. Actual: the original callback remains pending and the next transaction retries unchanged input until maxretry. Updating just one child path avoids the bug.
- Dominant language
- TypeScript
- Stars
- 5.2k
- Forks
- 1k
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 77
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from firebase/firebase-js-sdk
-
AI: ChatSession.sendMessage / sendMessageStream throw TypeError on blocked prompts (empty candidates) when tools are setPossibly taken @abhiramshaji-cyber claimed this today. Openapi: firebaseai
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
firebase/firebase-js-sdk#10641 ·
Maintainers usually reply within 1 day
-
api: firestore needs-attention question Repro Needed
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
firebase/firebase-js-sdk#10595 ·
Maintainers usually reply within 1 day
-
api: installations api: performance bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
firebase/firebase-js-sdk#10526 · 3 comments ·
Maintainers usually reply within 1 day
-
@firebase/firestore pins @grpc/grpc-js to ~1.9.0, holding consumers on a flagged releasePossibly taken @cherylEnkidu claimed this 50 days ago. Openapi: firestore needs-attention question stack:Angular
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
firebase/firebase-js-sdk#10400 · 4 comments · 9 reactions · 1 assignee ·
Maintainers usually reply within 1 day
-
Some (sub) package.json do not list the licences which lead to tools like syft report unknown licencePossibly taken @phoekerson claimed this 84 days ago. Openquestion
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
firebase/firebase-js-sdk#9326 · 5 comments ·
Maintainers usually reply within 1 day
All issues in firebase/firebase-js-sdk
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
inabagumi/shinju-date#7406 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
umami-software/umami#4787 ·
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day