question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: 13 INTERNAL: Received RST_STREAM with code 2 triggered by internal client error: read ECONNRESET

See original GitHub issue

i reuse a connection for all request , sometime seems connection will disconnect when idle for a long times (client error: read ECONNRESET), but the second time visit will be ok

how to set grpc-js for auto reconnect to avoid this error ?

Error: 13 INTERNAL: Received RST_STREAM with code 2 triggered by internal client error: read ECONNRESET
    at Object.callErrorFromStatus (/api/node_modules/@grpc/grpc-js/build/src/call.js:31:26)
    at Object.onReceiveStatus (/api/node_modules/@grpc/grpc-js/build/src/client.js:176:52)
    at Object.onReceiveStatus (/api/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:336:141)
    at Object.onReceiveStatus (/api/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:299:181)
    at /api/node_modules/@grpc/grpc-js/build/src/call-stream.js:145:78
    at processTicksAndRejections (node:internal/process/task_queues:76:11)
 {
  code: 13,
  details: 'Received RST_STREAM with code 2 triggered by internal client error: read ECONNRESET',
  metadata: Metadata { internalRepr: Map(0) {}, options: {} }
}

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:10
  • Comments:21 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
hfossli-agenscommented, May 27, 2022

I had exact same issue.

D 2022-05-25T09:19:37.476Z | call_stream | [14] ended with status: code=13 details="Received RST_STREAM with code 2 triggered by internal client error: Protocol error" 

I didn’t think the contents of the .env-file was deployed while I was deploying, but turns out firebase takes the contents of it:

FIRESTORE_EMULATOR_HOST="localhost:8080"
PUBSUB_EMULATOR_HOST="localhost:8085"
PUBSUB_PROJECT_ID="myrandomproject-local"

😱 These env-vars certainly shouldn’t have been deployed and the error makes sense. That’s why the Functions timed out when trying to connect with Firestore in my case. It is interesting that it times out rather than promptly failing.

1reaction
murgatroid99commented, Aug 19, 2021

@pROFESOR11 This problem is likely a bad interaction between how gRPC handles connections and how Firebase Cloud Functions networking works. I don’t expect to have a fix in the near future, but I can recommend the following to mitigate the problem:

  • Set a deadline based on the maximum latency that you can tolerate. It’s probably better to have the client get a “request timed out” error after 30 seconds or whatever and then retry than to wait 3 minutes for the response. Alternatively, you can set the deadline to about half the maximum latency you can tolerate and retry immediately in the function.
  • Enable keepalives by setting the grpc.keepalive_time_ms and grpc.keepalive_timeout_ms options to enable keepalive functionality. This will help the client detect that the server is unavailable more quickly. Importantly, on a serverless system like Firebase Cloud Functions, you should not set the option grpc.keepalive_permit_without_calls.

It seems that people commonly set grpc.keepalive_time_ms to 10000 (10 seconds) and grpc.keepalive_timeout_ms to 5000 (5 seconds), but the best values may change depending on the server you are talking to. For this mitigation to work optimally, the timeout you use to set the deadline should be at least slightly greater than the sum of those two values. One thing to watch for is if you start getting log lines that say “Connection to [address] rejected by server because of excess pings”, that means that your setting for grpc.keepalive_time_ms is too low.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix : Received RST_STREAM with error code 2 when ...
I have no problem when calling simple method, but when calling a streaming method like StreamingDetectIntent, I got an error during the request....
Read more >
Received RST_STREAM with code 2 triggered by internal ...
Hi! I'm getting Compilation error: Error: 13 INTERNAL: Received RST_STREAM with code 2 triggered by internal client error: read ECONNRESET ...
Read more >
Received RST_STREAM with code 2 triggered by internal ...
Error : 13 INTERNAL: Received RST_STREAM with code 2 triggered by internal client error: read ECONNRESET.
Read more >
Received RST_STREAM with code 2 (Internal server error)
Hi, I've received another server-generated grpc error on my ... [ERROR] 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error).
Read more >
grpc/grpc - Gitter
sending out gRPC client call and getting this error ... I'm getting Received RST_STREAM with code 2 (Internal server error) which I think...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found