Skip to content

Firestore emulator: resource starvation for concurrent operations on a single document #64

@merlinnot

Description

@merlinnot

I was instructed by @samtstern to post Firestore Emulator - related issues in this repository, so here we go:

Getting and setting the same reference (two concurrent operations) results in a lock. There are three possible outcomes:

  • operations succeed after a long period of time (~30+ seconds)
  • an UNKNOWN error is returned (code 2)
  • a GOAWAY message is returned

The issue is highly reproducible:

$ time npx ts-node ./test.ts 
2 UNKNOWN: 

real    0m32.538s
user    0m3.862s
sys     0m0.311s

Emulator output:

API endpoint: http://0.0.0.0:8080
If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:

   export FIRESTORE_EMULATOR_HOST=0.0.0.0:8080

Dev App Server is now running.

Mar 11, 2019 6:18:41 PM io.gapi.emulators.grpc.GrpcServer$3 operationComplete
INFO: Adding handler(s) to newly registered Channel.
Mar 11, 2019 6:18:41 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected HTTP/2 connection.
Mar 11, 2019 6:19:11 PM com.google.cloud.datastore.emulator.impl.util.WrappedStreamObserver onError
INFO: operation failed: null
Mar 11, 2019 6:19:11 PM com.google.cloud.datastore.emulator.impl.util.WrappedStreamObserver onError
INFO: operation failed: null

Repro:

import { Firestore } from '@google-cloud/firestore';
import { credentials } from 'grpc';

const firestore = new Firestore({
  'grpc.initial_reconnect_backoff_ms': 500,
  'grpc.max_reconnect_backoff_ms': 1000,
  port: 8080,
  projectId: 'test',
  servicePath: 'localhost',
  sslCreds: credentials.createInsecure(),
});

const ref = firestore.collection('collection').doc('doc');

const run = async () => {
  await Promise.all([ref.get(), ref.set({})]);
};

run().catch(x => console.error(x.message));

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions