Skip to content
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

RST_STREAM error keeps showing up #1023

Open
jakeleventhal opened this issue Apr 16, 2020 · 152 comments
Open

RST_STREAM error keeps showing up #1023

jakeleventhal opened this issue Apr 16, 2020 · 152 comments
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@jakeleventhal
Copy link

Environment details

  • OS: macOS Catalina 10.15.5 Beta (19F53f)
  • Node.js version: 13.7.0
  • npm version: 6.13.6
  • @google-cloud/firestore version: 3.7.4

Steps to reproduce

This error keeps appearing over and over in my logs (not regularly reproducible):

Error: 13 INTERNAL: Received RST_STREAM with code 2
at Object.callErrorFromStatus (/api/node_modules/@grpc/grpc-js/src/call.ts:81)
at Object.onReceiveStatus (/api/node_modules/@grpc/grpc-js/src/client.ts:324)
at Object.onReceiveStatus (/api/node_modules/@grpc/grpc-js/src/client-interceptors.ts:439)
at Object.onReceiveStatus (/api/node_modules/@grpc/grpc-js/src/client-interceptors.ts:402)
at Http2CallStream.outputStatus (/api/node_modules/@grpc/grpc-js/src/call-stream.ts:228)
at Http2CallStream.maybeOutputStatus (/api/node_modules/@grpc/grpc-js/src/call-stream.ts:278)
at Http2CallStream.endCall (/api/node_modules/@grpc/grpc-js/src/call-stream.ts:262)
at ClientHttp2Stream.<anonymous> (/api/node_modules/@grpc/grpc-js/src/call-stream.ts:532)
at ClientHttp2Stream.emit (events.js:315)
at ClientHttp2Stream.EventEmitter.emit (domain.js:485)
at emitErrorCloseNT (internal/streams/destroy.js:76)
at processTicksAndRejections (internal/process/task_queues.js:84)
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/nodejs-firestore API. label Apr 16, 2020
@jakeleventhal jakeleventhal changed the title Bandwidth exhausted consistently showing up RST_STREAM error keeps showing up Apr 16, 2020
@bcoe bcoe added the type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. label Apr 16, 2020
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Apr 17, 2020
@schmidt-sebastian
Copy link
Contributor

@jakeleventhal Thanks for filing this. Do you know at all what type of request/API call this is related to?

@jakeleventhal
Copy link
Author

The only place i use grpc is via firestore so it must be something from there. I don't really have more info unfortunately

@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Apr 21, 2020
@BenWhitehead BenWhitehead added priority: p2 Moderately-important priority. Fix may not be included in next release. and removed 🚨 This issue needs some love. triage me I really want to be triaged. labels May 8, 2020
@whyvrafvr
Copy link

I also got this one with firebase-admin 8.12.1 :

{"error":"Error: 13 INTERNAL: Received RST_STREAM with code 2
    at Object.callErrorFromStatus (/usr/src/app/node_modules/@grpc/grpc-js/build/src/call.js:30:26)
   at Object.onReceiveStatus (/usr/src/app/node_modules/@grpc/grpc-js/build/src/client.js:175:52)
    at Object.onReceiveStatus ...

@whyvrafvr
Copy link

This is a weird jeopardize issue, thrown during delete as create or whatever request type...

@schmidt-sebastian
Copy link
Contributor

All document modifications (e.g. delete(), create()) use the same underlying request type. This request type is not safe for automatic retry, so unfortunately we cannot simply retry these errors.

@whyvrafvr
Copy link

whyvrafvr commented May 20, 2020

Hi @schmidt-sebastian.
I do confirm the request type is not safe.
Retrying many times the same call (and so, the same request, I guess) has no significant effect.
But there is no error when the nodejs instance is restarted : I guess a GRPC subroutine is hanging out.

@whyvrafvr
Copy link

After a while, errors, as mentioned by @jakeleventhal, are thrown and it’s not possible to persist data in firestore and an instance restart is required. That’s a real problem folks 😄
FYI, I’ve no issue using firestore delete(), create() methods with Go...

@schmidt-sebastian
Copy link
Contributor

schmidt-sebastian commented May 20, 2020

@Skonx To rule out that this is a problem with our backend, can you send me your project ID and the time at which you saw these repeated failures? My email is mrschmidt<at>google.com.

If it is not a backend issue, we likely need GRPC logs from to further diagnose these failures. These can be obtained by setting two environment variables: GRPC_TRACE=all, GRPC_VERBOSITY=DEBUG

Note that this create a lot of logs, so hopefully this is not something we have to look at.

@whyvrafvr
Copy link

whyvrafvr commented May 20, 2020

Yep. I've replied to your google.com email address.
I will enable the environment variables asap and keep you post.

@ConorEB
Copy link

ConorEB commented May 26, 2020

Hello! We also experience the same error usually coupled with
Error: 8 RESOURCE_EXHAUSTED: Bandwidth exhausted

We noticed that it usually fails all at once and then recovers very quickly.

@sk-
Copy link
Contributor

sk- commented May 26, 2020

We are also affected by this error. A month before, it was a sporadic error, maybe once a week, and now we are seeing it many times per day.

@merlinnot
Copy link

I'm also experiencing the issue for over a month now, with a couple hundred to a few thousand errors per day:

  • Error: 13 INTERNAL: Received RST_STREAM with code 2
  • Error: 14 UNAVAILABLE: Stream refused by server

@schmidt-sebastian I opened a support case if you need a project ID or other information: 23689958.

@zenati
Copy link

zenati commented May 29, 2020

Same problem here: Received RST_STREAM with code 2

@ConorEB
Copy link

ConorEB commented May 29, 2020

We were able to resolve the Error: 8 RESOURCE_EXHAUSTED: Bandwidth exhausted by upgrading to a nodejs12 runtime on App Engine and updating Electron to the newly released v9 version. So far we have not seen it again in production since the root cause was related to the node js patch:
https://nodejs.org/en/blog/release/v12.14.1/

[9fd6b5e98b] - http2: fix session memory accounting after pausing (Michael Lehenbauer) #30684

After the update, the various other DB related errors have also gone away, including Received RST_STREAM with code 2.

We currently use Electron in a Google App Engine project and work in the standard runtime. Google has not updated its images to include some necessary libs for the new version of Electron. We were able to work around this as Google supports these libs in Puppeteer, so we installed Puppeteer and sent a deploy off to our production server (on a no-promote flag). After doing so, our best guess is that Google rebuilt our server images with the needed libs to run Puppeteer, which in turn allowed us to run the new version of Electron.

I hope this information helps! We spent a lot of time diving into this, so if you have any questions, feel free to respond below.

@schmidt-sebastian
Copy link
Contributor

schmidt-sebastian commented May 30, 2020

Our backend team has looked at the projects that were sent to us. There are no indications that your errors correlate with errors on the backend, which makes it likely that this is a client side issue. I will continue to investigate possible root causes.

@schmidt-sebastian
Copy link
Contributor

As of v3.8.5, we are now retrying RunQuery requests that fail with RST_STREAM. If this error shows up again, we can evaluate expanding our retry to other SDK methods as well.

@merlinnot
Copy link

@schmidt-sebastian I've been running on v3.8.5 for the entire day, I still see RST_STREAM.

I checked my code to see for which usage patterns does it occur:

  • await reference.set()
  • await batch.commit()
  • await reference.update()

Can we please reopen this issue for visibility?

@schmidt-sebastian
Copy link
Contributor

@merlinnot We continue to receive pushback on retrying RST_STREAM/INTERNAL for Commit RPCs. I hope your comment is enough to convince the respective folks that we should retry.

@michaelAtCoalesce
Copy link

michaelAtCoalesce commented Jun 13, 2022

hey all - on @grpc/grpc-js version 1.6.0 - i got errors like this -
{"code":4,"details":"The datastore operation timed out, or the data was temporarily unavailable.","metadata":{},"note":"Exception occurred in retry method that was not classified as transient"}

{"code":4,"details":"The datastore operation timed out, or the data was temporarily unavailable.","metadata":{},"note":"Exception occurred in retry method that was not classified as transient"} Error: 4 DEADLINE_EXCEEDED: The datastore operation timed out, or the data was temporarily unavailable

GoogleError; {"code":4} Error: Total timeout of API google.firestore.v1.Firestore exceeded 600000 milliseconds before any response was received.

with the NEWER version of @grpc/grpc-js 1.6.7 - for the same case i got the following errors.

{"code":1,"details":"Call cancelled","metadata":{},"note":"Exception occurred in retry method that was not classified as transient"} Error: 1 CANCELLED: Call cancelled

So, basically I'm still getting errors with a highly parallel write scenario - but now I'm getting "Call Cancelled" with grpc v1.6.7, versus "DEADLINE_EXCEEDED" with v 1.6.0.

whats the meaning behind Call Cancelled..? googling this - it looks like it is OK to retry these if the write is idempotent?

@MiguelNiblock
Copy link

I'm getting this error when using firebase from within cypress and connecting it to emulator for e2e testing. I can't make any requests to populate the database because of this error.

@michaelAtCoalesce
Copy link

an update from my end - we had to rearchitect our data layout to avoid more than one write to a document per second (This is described in the best practices for firestore) https://firebase.google.com/docs/firestore/best-practices#updates_to_a_single_document

i've never heard of a data store that limits you to 1 write per second.... but whatever.

the thing is, you can get away with having a few writes to a document for a second, but if you start doing it at scale and highly parallel, you are 1) more likely to get the issue 2) less likely to be able to just retry and have the write succeed.

i put in a retry of 3, and was still unable to get a successful write when dealing with hundreds of concurrent writes.

so, although i do think that firestore should really work on these issues and not have weird best practices like 1 write a second - we were able to rewrite our app to get things to succeed (with minimal retrying)

@untdecocs
Copy link

Trying to write to collection. Protocol error. No info anywhere. What should be done ?

"firebase-admin": "^11.5.0"

image

@ziedHamdi
Copy link

ziedHamdi commented Apr 13, 2023

Happens to me with the emulator on every attempt, so maybe an easy case to reproduce

Error: 13 INTERNAL: Received RST_STREAM with code 2 triggered by internal client error: Protocol error
    at callErrorFromStatus (/home/zied/Work/WS/linkedinCv-back/node_modules/.pnpm/@grpc+grpc-js@1.8.13/node_modules/@grpc/grpc-js/build/src/call.js:31:19)
    at Object.onReceiveStatus (/home/zied/Work/WS/linkedinCv-back/node_modules/.pnpm/@grpc+grpc-js@1.8.13/node_modules/@grpc/grpc-js/build/src/client.js:192:76)
    at Object.onReceiveStatus (/home/zied/Work/WS/linkedinCv-back/node_modules/.pnpm/@grpc+grpc-js@1.8.13/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:360:141)
    at Object.onReceiveStatus (/home/zied/Work/WS/linkedinCv-back/node_modules/.pnpm/@grpc+grpc-js@1.8.13/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:323:181)
    at /home/zied/Work/WS/linkedinCv-back/node_modules/.pnpm/@grpc+grpc-js@1.8.13/node_modules/@grpc/grpc-js/build/src/resolving-call.js:94:78
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
for call at
    at ServiceClientImpl.makeUnaryRequest (/home/zied/Work/WS/linkedinCv-back/node_modules/.pnpm/@grpc+grpc-js@1.8.13/node_modules/@grpc/grpc-js/build/src/client.js:160:34)
    at ServiceClientImpl.<anonymous> (/home/zied/Work/WS/linkedinCv-back/node_modules/.pnpm/@grpc+grpc-js@1.8.13/node_modules/@grpc/grpc-js/build/src/make-client.js:105:19)
    at /home/zied/Work/WS/linkedinCv-back/node_modules/.pnpm/@google-cloud+firestore@6.5.0/node_modules/@google-cloud/firestore/build/src/v1/firestore_client.js:227:29
    at /home/zied/Work/WS/linkedinCv-back/node_modules/.pnpm/google-gax@3.6.0/node_modules/google-gax/build/src/normalCalls/timeout.js:44:16
    at repeat (/home/zied/Work/WS/linkedinCv-back/node_modules/.pnpm/google-gax@3.6.0/node_modules/google-gax/build/src/normalCalls/retries.js:80:25)
    at /home/zied/Work/WS/linkedinCv-back/node_modules/.pnpm/google-gax@3.6.0/node_modules/google-gax/build/src/normalCalls/retries.js:118:13
    at OngoingCallPromise.call (/home/zied/Work/WS/linkedinCv-back/node_modules/.pnpm/google-gax@3.6.0/node_modules/google-gax/build/src/call.js:67:27)
    at NormalApiCaller.call (/home/zied/Work/WS/linkedinCv-back/node_modules/.pnpm/google-gax@3.6.0/node_modules/google-gax/build/src/normalCalls/normalApiCaller.js:34:19)
    at /home/zied/Work/WS/linkedinCv-back/node_modules/.pnpm/google-gax@3.6.0/node_modules/google-gax/build/src/createApiCall.js:84:30
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Caused by: Error
    at WriteBatch.commit (/home/zied/Work/WS/linkedinCv-back/node_modules/.pnpm/@google-cloud+firestore@6.5.0/node_modules/@google-cloud/firestore/build/src/write-batch.js:433:23)
    at DocumentReference.set (/home/zied/Work/WS/linkedinCv-back/node_modules/.pnpm/@google-cloud+firestore@6.5.0/node_modules/@google-cloud/firestore/build/src/reference.js:393:27)
    at POST (/home/zied/Work/WS/linkedinCv-back/src/routes/cv/submit/+server.js:20:83)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Module.render_endpoint (/node_modules/.pnpm/@sveltejs+kit@1.15.2_svelte@3.58.0_vite@4.2.1/node_modules/@sveltejs/kit/src/runtime/server/endpoint.js:47:20)
    at async resolve (/node_modules/.pnpm/@sveltejs+kit@1.15.2_svelte@3.58.0_vite@4.2.1/node_modules/@sveltejs/kit/src/runtime/server/respond.js:378:17)
    at async Object.handle (/src/hooks.server.js:7:19)
    at async Module.respond (/node_modules/.pnpm/@sveltejs+kit@1.15.2_svelte@3.58.0_vite@4.2.1/node_modules/@sveltejs/kit/src/runtime/server/respond.js:251:20)
    at async file:///home/zied/Work/WS/linkedinCv-back/node_modules/.pnpm/@sveltejs+kit@1.15.2_svelte@3.58.0_vite@4.2.1/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:514:22 {
  code: 13,
  details: 'Received RST_STREAM with code 2 triggered by internal client error: Protocol error',
  metadata: Metadata { internalRepr: Map(0) {}, options: {} },
  note: 'Exception occurred in retry method that was not classified as transient'
}


package.json

{
	"name": "linkedincv-back",
	"version": "0.0.1",
	"private": true,
	"scripts": {
		"dev": "vite dev",
		"build": "vite build",
		"preview": "vite preview",
		"check": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json",
		"check:watch": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json --watch",
		"test": "playwright test",
		"test:unit": "vitest",
		"lint": "prettier --plugin-search-dir . --check .",
		"format": "prettier --plugin-search-dir . --write ."
	},
	"devDependencies": {
		"@playwright/test": "^1.28.1",
		"@sveltejs/adapter-auto": "^2.0.0",
		"@sveltejs/kit": "^1.5.0",
		"acorn": "^8.8.2",
		"estree-walker": "^3.0.3",
		"prettier": "^2.8.0",
		"prettier-plugin-svelte": "^2.8.1",
		"svelte": "^3.54.0",
		"svelte-check": "^3.0.1",
		"typescript": "^5.0.0",
		"vite": "^4.2.0",
		"vitest": "^0.25.3"
	},
	"type": "module",
	"dependencies": {
		"firebase-admin": "^11.6.0",
		"mongoose": "^7.0.3",
		"svelte-routing": "^1.6.0"
	}
}

Under Node.js /sveltekit server endpoint. Here are my lib versions:


pnpm view firebase-admin dependencies

{
  '@fastify/busboy': '^1.1.0',
  '@firebase/database-compat': '^0.3.0',
  '@firebase/database-types': '^0.10.0',
  '@types/node': '>=12.12.47',
  jsonwebtoken: '^9.0.0',
  'jwks-rsa': '^3.0.1',
  'node-forge': '^1.3.1',
  uuid: '^9.0.0',
  '@google-cloud/firestore': '^6.4.0',
  '@google-cloud/storage': '^6.5.2'
}

My use case is pretty simple:
firebaseInit.js:

import admin from 'firebase-admin'
const useEmulator = true;

if (useEmulator){
	process.env['FIRESTORE_EMULATOR_HOST'] = 'localhost:4000';
}

// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
	apiKey: "XXXXX",
	authDomain: "linkedincv-bdbec.firebaseapp.com",
	projectId: "linkedincv-bdbec",
	storageBucket: "linkedincv-bdbec.appspot.com",
	messagingSenderId: "XXXXX",
	appId: "XXXXX",
	measurementId: "XXXXX",
};

// Initialize Firebase
const app = admin.initializeApp(firebaseConfig);
// const db = getFirestore(app);

const db = admin.firestore();

export {app, db}

My code using the initialized db variable:

+server.js

import { json } from '@sveltejs/kit';
import {db} from '../../../lib/middleware/firebaseInit'

export async function POST({request}) {
	try {
		const payload = await request.json();
		const uniqueUrl = payload.uniqueUrl;

		const docRef = await db.collection("json_cv").doc("zied").set( payload)
		// Return the document ID of the stored object
		return json({
			body: JSON.stringify({ documentId: docRef.id }),
			headers: { 'Content-Type': 'application/json' },
			status: 200
		});
	} catch (error) {
		// Handle any errors that occur during processing
		console.error(error);
		return json({
			body: JSON.stringify({ error }),
			headers: { 'Content-Type': 'application/json' },
			status: 500
		});
	}
}

Just to be complete if you want to reproduce, here's a file specific to sveltekit allowing CORS
hooks.server.js

import { Handle } from '@sveltejs/kit';

export const handle = async ({ resolve, event }) => {
	const response = await resolve(event);

	// Apply CORS header for API routes
	if (event.url.pathname.startsWith('/cv/submit')) {
		// Required for CORS to work
		if(event.request.method === 'OPTIONS') {
			return new Response(null, {
				headers: {
					'Access-Control-Allow-Methods': 'POST, GET, OPTIONS, DELETE',
					'Access-Control-Allow-Origin': '*',
				}
			});
		}

		response.headers.append('Access-Control-Allow-Origin', `*`);
	}

	return response;
}; 

@ziedHamdi
Copy link

That change has been released, so if you update your dependencies, you should get it. Please try it out to see if it helps.

I would like to note that @michaelAtCoalesce was able to share a consistent reproduction of the error, and that was a great help with tracking down the bug we found. So if anyone else encounters a similar error, a similar reproduction would probably be helpful for that too.

Do you want the reproduction to be in a git repo? or is the code I shared here sufficient?

@ziedHamdi
Copy link

I'm getting this error when using firebase from within cypress and connecting it to emulator for e2e testing. I can't make any requests to populate the database because of this error.

Same for me

@ziedHamdi
Copy link

Running finebase init again, things solved. I recommend doing it in case you forgot to correctly initialize something (I think I surely did, as I was discovering firebase)

@marcianosr
Copy link

marcianosr commented May 2, 2023

@ziedHamdi What was your solution? I ran firebase base init also again, but to no avail.

@jakeleventhal
Copy link
Author

jakeleventhal commented May 8, 2023

Update: I ended up moving off of Firestore and moved to a Postgres DB, and ultimately everything from GCP to AWS because of this issue.

@MorenoMdz
Copy link

MorenoMdz commented Aug 3, 2023

Hello, Same issue here, across all our prod servers. The error rate is extremely high, but it's in our snapshot listeners, not the writes. "firebase-admin": "~9.11.0", node 14

Same here, we have millions of error spans with microseconds duration in our server due to this. Our system initializes a snapshot listeners to get changes on a specific document we have to control our feature flags, it should only instantiate once when a new instance of our NestJs server boots up and then only be called when changes happen, but we get millions of those small 10 micro second errors due to DNS errors, connection errors and now RST_STREAM.

Our server is hosted in Render.com, ALL the normal Firestore calls work as expected, no requests ever failed because of this, the snapshot listener is just erroring out like this, all the time.

I tried contacting GCP support on this, they have zero clues about what is the problem or how to try to help as they don't see any errors on their side.

image image image image image

@FilledStacks
Copy link

I just finished my backend local development and everything work well. Then I deployed and none of my functions work. I'm getting the same error.

Error: 13 INTERNAL: Received RST_STREAM with code 2 triggered by internal client error: Protocol error
    at callErrorFromStatus (/workspace/node_modules/@grpc/grpc-js/build/src/call.js:31:19)
    at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client.js:192:76)
    at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:360:141)
    at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:323:181)
    at /workspace/node_modules/@grpc/grpc-js/build/src/resolving-call.js:94:78
    at processTicksAndRejections (node:internal/process/task_queues:78:11)

My code is pretty simple.

this.#log.i(`create license`, JSON.stringify({license: license, id: id}));

const licenseDoc = this.ref.doc(id);

await licenseDoc.set(license); // <===== This is where the error originates from 
return licenseDoc.id;

Using Node.js 16

I don't get it once or twice, it literally happens everytime. My endpoint doesn't work at all. This is a brand new project on Firestore and my first deployment.

Package.json dependencies

 "dependencies": {
    "firebase-admin": "^11.10.1",
    "firebase-backend": "^0.2.5",
    "firebase-functions": "^4.4.1",
    "uuid": "^9.0.1"
  },

Is there anything I can try to get past this? We need to launch our product and I'd hate to need another week to rewrite all these endpoints on a different platform.

@maylorsan
Copy link

maylorsan commented Oct 21, 2023

👋 @schmidt-sebastian,

We've been facing this error in our production environment for the past 3 days and it's occurred roughly 10,600 times:

Error: 13 INTERNAL: Received RST_STREAM with code 1

image

The error is triggered when executing the following code:

const writeResult = await admin
      .firestore()
      .collection(FirestoreCollections.Users)
      .doc(userID)
      .update(fieldsToUpdate); // This line throws the error

Do we have any updates or workarounds for this? It's affecting our users and we'd appreciate your guidance.

Note: Our Users collection has a significantly large number of documents. Could the volume of documents be a contributing factor to this issue?

@CollinsVizion35
Copy link

CollinsVizion35 commented Oct 22, 2023

@maylorsan

13 INTERNAL: Received RST_STREAM with code 2

Have you found a solution to this? because i am facing the same exact error.

@maylorsan
Copy link

Hello @CollinsVizion35,

We haven't found a solution to this issue yet.

We've attempted several methods, but none have resolved the problem:

  • Switched the update method to use set and set with {merge: true}, but this didn't work.
  • Created a new cloud function dedicated solely to this method. Surprisingly, it didn't work either. However, it's noteworthy that we have several other cloud functions that update user data using the same method, and they function as expected.
    What's even more perplexing is that this issue arises in about 60% of our http cloud function calls, and it seems to occur randomly. We haven't been able to identify a consistent pattern.

Interestingly, everything operates flawlessly in our development project. The only difference is that the development project has a smaller User collection.

I'm starting to suspect that this might be related to some undocumented limitation in Firestore...

I will stay in touch about updates!

@CollinsVizion35
Copy link

CollinsVizion35 commented Oct 22, 2023

@maylorsan

Okay, thank you. I tried using batch commit and it still didn't work.

@edmilsonss
Copy link

I've got a workaround/solution in my situation

See here: firebase/firebase-admin-node#2345 (comment)

@CollinsVizion35
Copy link

CollinsVizion35 commented Oct 24, 2023

Hey @maylorsan, i think i have found a solution from @edmilsonss

I think it works with these changes

former code:
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://project name.firestore.googleapis.com",
});

// Create a Firestore instance
const db = admin.firestore();

new code:
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://project name.firestore.googleapis.com",
});

// Create a Firestore instance
const db = admin.firestore();
const settings = {
preferRest: true,
timestampsInSnapshots: true
};
db.settings(settings);

@maylorsan
Copy link

maylorsan commented Oct 24, 2023

@CollinsVizion35 Indeed, we haven't experimented with that solution just yet. As I mentioned in this comment, our primary approach was to optimize our algorithm logic between Firebase calls. Thankfully, this seems to have resolved the issue for now.

It's certainly an unusual behavior 😄

@udnes99
Copy link

udnes99 commented Nov 6, 2023

Any update on this issue? Happens sporadically for us in production, using @google-cloud/datastore": "8.2.2" and as I understood, googleapis/nodejs-datastore#679 has been closed in favor of using this issue as it is likely the same root cause. This has been happening for a long time..

This seems to be occurring when instantiating too many transactions simultaneously, perhaps it initiates too many gRPC connections to the google API?

@sammyKhan
Copy link

@maylorsan Setting preferRest: true fixes it for one of our simpler services, but not for others. We are not using firestore listeners in any of them, so I'm surprised it's switching to http streaming from REST at all. Could you give a list of situations in which preferRest will fall back to http streaming so that we can try to avoid them?

@maylorsan
Copy link

maylorsan commented Dec 5, 2023

@sammyKhan, my apologies for the delayed reply!

I wanted to clarify that we don't employ preferRest: true in our services, as previously mentioned. Our main strategy has been to refine the logic of our algorithm, especially in the intervals between Firebase calls.

our primary approach was to optimize our algorithm logic between Firebase calls

In our case it appears that the issue we're encountering arises due to a significant delay occurring between the get and update methods in Firestore.

@cherylEnkidu
Copy link
Contributor

Hi @maylorsan

Since your case is different to what is been reported in this issue, could you please open a new ticket and describe your problem in detail?

@maylorsan
Copy link

Hi @cherylEnkidu,

Thanks for the advice. I'll open a new ticket with all relevant details to address our specific Firestore issue.

@adamkoch
Copy link

We still see this intermittently, no real pattern that I can see. The Firestore code that triggers it is simple and runs successfully 99% of the time:

await ref.set(updateData, {
  merge: true,
});

But every so often we'll see the error. I've been progressively adding more debugging logging to the function to see if I can work out what may be causing it but there is nothing of note that I can see.

Using up-to-date dependencies and node version.

~/ $ node --version
v18.18.2

package.json dependencies:

  "dependencies": {
    "@google-cloud/firestore": "^7.3.0",
    "@google-cloud/logging": "^11.0.0",
    "firebase-admin": "^12.0.0",
    "firebase-functions": "^4.7.0",
    "googleapis": "^132.0.0",
    ...
  },

Stack trace:

Error: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error) Error: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error)
    at callErrorFromStatus (/workspace/node_modules/@grpc/grpc-js/build/src/call.js:31:19)
    at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client.js:192:76)
    at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:360:141)
    at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:323:181)
    at /workspace/node_modules/@grpc/grpc-js/build/src/resolving-call.js:99:78
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
for call at
    at ServiceClientImpl.makeUnaryRequest (/workspace/node_modules/@grpc/grpc-js/build/src/client.js:160:32)
    at ServiceClientImpl.<anonymous> (/workspace/node_modules/@grpc/grpc-js/build/src/make-client.js:105:19)
    at /workspace/node_modules/@google-cloud/firestore/build/src/v1/firestore_client.js:231:29
    at /workspace/node_modules/google-gax/build/src/normalCalls/timeout.js:44:16
    at repeat (/workspace/node_modules/google-gax/build/src/normalCalls/retries.js:80:25)
    at /workspace/node_modules/google-gax/build/src/normalCalls/retries.js:118:13
    at OngoingCallPromise.call (/workspace/node_modules/google-gax/build/src/call.js:67:27)
    at NormalApiCaller.call (/workspace/node_modules/google-gax/build/src/normalCalls/normalApiCaller.js:34:19)
    at /workspace/node_modules/google-gax/build/src/createApiCall.js:84:30
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Caused by: Error
    at WriteBatch.commit (/workspace/node_modules/@google-cloud/firestore/build/src/write-batch.js:432:23)
    at DocumentReference.set (/workspace/node_modules/@google-cloud/firestore/build/src/reference.js:398:27)
    at /workspace/lib/auth.js:201:19
    at Generator.next (<anonymous>)
    at fulfilled (/workspace/lib/auth.js:5:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 13,
  details: 'Received RST_STREAM with code 2 (Internal server error)',
  metadata: Metadata { internalRepr: Map(0) {}, options: {} },
  note: 'Exception occurred in retry method that was not classified as transient'
}
    at console.error (/workspace/node_modules/firebase-functions/lib/logger/compat.js:31:23)
    at /workspace/lib/auth.js:207:17
    at Generator.throw (<anonymous>)
    at rejected (/workspace/lib/auth.js:6:65)

@adi-rds
Copy link

adi-rds commented Mar 1, 2024 via email

@looker-colmeia
Copy link

looker-colmeia commented Apr 30, 2024

any news on this issue? 2 years with the same problem here at the company, we tried

const datastore = new Datastore({fallback:'rest'});

but it's too slow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests