firebase / firebase/firebase-tools
Firestore emulator not throwing an error for oversized batches
- Dominant language
- TypeScript
- Stars
- 4.5k
- Forks
- 1.3k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 84
Description
### \[REQUIRED] Environment info
**firebase-tools:** 13.11.0 (also present in latest major v14)
**Platform:** macOS 15.3.2
### \[REQUIRED] Test case
We have a custom utility that splits a big batch into multiple smaller batches if it would be too much data for a single batch to handle. For the sake of simplicity, the minimal repro won't consider the utility and reproduce the issue itself.
We are testing Firestore emulator behavior with an oversized `WriteBatch` to simulate and handle the `Transaction too big. Decrease transaction size` error.
**Minimal repro:**
```ts
import { initializeApp } from 'firebase-admin/app';
import { getFirestore } from 'firebase-admin/firestore';
process.env.FIRESTORE_EMULATOR_HOST = 'localhost:5001'
const app = initializeApp({ /* init for emulator */ });
const firestore = getFirestore(app);
const batch = firestore.batch();
const collection = firestore.collection('test_batch');
const largeString = 'a'.repeat(8000); // ~8KB payload
for (let i = 0; i < 1500; i++) {
const ref = collection.doc();
batch.set(ref, {
field: 'value',
largeString, // 8kb * 1500 = 12mb~
});
}
await batch.commit(); // <-- Should throw
```
### \[REQUIRED] Steps to reproduce
1. Use any `firebase-tools` since `13.11.0` . This behaviour is not present in previous versions.
2. Start the Firestore emulator (`firebase emulators:start --only firestore`)
3. Run the script above (in a test or standalone)
4. Observe result with emulator 1.19.4 vs 1.19.7
### \[REQUIRED] Expected behavior
The commit should throw:
```
Error: 3 INVALID_ARGUMENT: Transaction too big. Decrease transaction size.
```
This allows code to detect and respond to the error, e.g., by splitting the batch.
This is an example of a **production** (non emulated firestore) stack trace for this scenario:
```
Error: 3 INVALID_ARGUMENT: Transaction too big. Decrease transaction size.
at Object.callErrorFromStatus (/app/node_modules/@google-cloud/firestore/node_modules/@grpc/grpc-js/build/src/call.js:31:19)
at Object.onReceiveStatus (/app/node_modules/@google-cloud/firestore/node_modules/@grpc/grpc-js/build/src/client.js:190:52)
at Object.onReceiveStatus (/app/node_modules/@google-cloud/firestore/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:365:141)
at Object.onReceiveStatus (/app/node_modules/@google-cloud/firestore/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:328:181)
at /app/node_modules/@google-cloud/firestore/node_modules/@grpc/grpc-js/build/src/call-stream.js:188:78
at process.processTicksAndRejections (node:internal/process/task_queues:85:11)
for call at
at ServiceClientImpl.makeUnaryRequest (/app/node_modules/@google-cloud/firestore/node_modules/@grpc/grpc-js/build/src/client.js:160:30)
at ServiceClientImpl. (/app/node_modules/@google-cloud/firestore/node_modules/@grpc/grpc-js/build/src/make-client.js:105:19)
```
I also manually replaced the `firestore` emulator version inside my `node_modules` and confirmed that the issue is with the emulator itself, not this package or `firebase-admin`.
### \[REQUIRED] Actual behavior
Since upgrading to emulator 1.19.7:
* No error is thrown
* The script/test **hangs indefinitely**
* Emulator logs show no failure or response
Rolling back to emulator 1.19.4 restores the expected behavior.
This regression makes it impossible to test batch-splitting logic locally or in CI. Please advise if this is a known change in emulator behavior or a bug.
Thanks for your work on these tools!
Contributor guide
Assessment
This issue has not been assessed yet.