Skip to content
Latchkey

gRPC "Received RST_STREAM with code 2" (CANCEL) in CI

RST_STREAM is the HTTP/2 frame that abruptly terminates a stream. Code 2 corresponds to CANCEL. gRPC surfaces "Received RST_STREAM with code 2" when the peer cancels the stream before it completes.

What this error means

A streaming RPC fails with "Error: 1 CANCELLED: Received RST_STREAM with code 2" or "8 RESOURCE_EXHAUSTED: ... RST_STREAM". It appears when a client cancels early or the server aborts the stream.

gRPC
Error: 1 CANCELLED: Received RST_STREAM with code 2 (Internal server error)
    at callErrorFromStatus (node_modules/@grpc/grpc-js/build/src/call.js:...)

Common causes

The client cancelled the stream early

A test that ends before consuming the whole stream (or an aborted context) sends RST_STREAM CANCEL, which the peer reports.

The server aborted the stream

A server that resets the stream on an internal error emits RST_STREAM with code 2, cancelling the in-flight RPC.

How to fix it

Consume the stream to completion before asserting

  1. Await the stream end event before ending the test.
  2. Do not cancel or destroy the call until all expected messages arrive.
  3. Handle the error event so a cancel is reported clearly.
test.mjs
await new Promise((resolve, reject) => {
  stream.on('data', collect);
  stream.on('end', resolve);
  stream.on('error', reject);
});

Investigate a server-side reset

If the server initiates the RST_STREAM, read its logs for the internal error that caused the abort and fix that path.

How to prevent it

  • Fully consume streams before ending the test.
  • Avoid cancelling calls before the expected data arrives.
  • Read server logs when the reset originates server-side.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →