title: How to keep grpc-js client connection open (alive) during inactive times?
body: <p>I have a grpc server streaming RPC that communicates with the client. The client throws an error when it does not receive communication from the server. The error is:</p>
  <pre><code>Error: 13 INTERNAL: Received RST_STREAM with code 2
      at Object.callErrorFromStatus (/app/node_modules/@grpc/grpc-js/build/src/call.js:30:26)
      at Object.onReceiveStatus (/app/node_modules/@grpc/grpc-js/build/src/client.js:328:49)
      at Object.onReceiveStatus (/app/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:304:181)
      at Http2CallStream.outputStatus (/app/node_modules/@grpc/grpc-js/build/src/call-stream.js:116:74)
      at Http2CallStream.maybeOutputStatus (/app/node_modules/@grpc/grpc-js/build/src/call-stream.js:155:22)
      at Http2CallStream.endCall (/app/node_modules/@grpc/grpc-js/build/src/call-stream.js:141:18)
      at ClientHttp2Stream.stream.on (/app/node_modules/@grpc/grpc-js/build/src/call-stream.js:410:22)
      at ClientHttp2Stream.emit (events.js:198:13)
      at emitCloseNT (internal/streams/destroy.js:68:8)
      at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
  Emitted 'error' event at:
      at Object.onReceiveStatus (/app/node_modules/@grpc/grpc-js/build/src/client.js:328:28)
      at Object.onReceiveStatus (/app/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:304:181)
      [... lines matching original stack trace ...]
      at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
      at process._tickCallback (internal/process/next_tick.js:63:19)
  </code></pre>
  <p>I have tried searching for solutions and the only &quot;solution&quot; that kept the connection open was to manually ping the client every 10 seconds using <code>setInterval</code>. I read that grpc is supposed to keep the connections open for you and even reconnect if it is lost <a href="https://www.cncf.io/blog/2018/08/31/grpc-on-http-2-engineering-a-robust-high-performance-protocol/" rel="nofollow noreferrer">in this article</a>.</p>
  <blockquote>
  <p>As mentioned above, KeepAlive provides a valuable benefit: periodically checking the health of the connection by sending an HTTP/2 PING to determine whether the connection is still alive.</p>
  </blockquote>
  <p>The way I set up the client is below</p>
  <pre><code>var grpc = require('@grpc/grpc-js');
  require('dotenv').config({path:'/app/.env'});
  var responderProto = grpc.loadPackageDefinition(packageDefinition).responder;
  var client = new responderProto.ResponderService(process.env.GRPC_HOST_AND_PORT,
          grpc.credentials.createInsecure(),
          {
              &quot;grpc.http2.max_pings_without_data&quot; : 0,
              &quot;grpc.keepalive_time_ms&quot;: 10000,
              &quot;grpc.keepalive_permit_without_calls&quot; : 1
  
          });
  </code></pre>
  <p>My understanding was that the <code>&quot;grpc.keepalive_time_ms&quot;</code> is supposed to ping the server every <code>x ms</code></p>
  <p>Am I doing something wrong or missing or misunderstanding something essential?</p>