JamesAri
JamesAri

Reputation: 11

Wait-For-Ready in grpc-js

I have been reading about Wait-For-Ready in gRPC and wanted to enable it in my app. I'm using @grpc-js and after digging into the library code (since I couldn't find any documentation about Wait-For-Ready option, only the client's waitForReady callback) it seems that it accepts the option through metadata:

metadata.set('waitForReady', true)

The problem is that I would like to test if it really did set the option but I don't know how (tried setting GRPC_TRACE=all GRPC_VERBOSITY=DEBUG but nothing in the logs).

Also, I would prefer to set this option via service config, would this work?:

const serviceConfig = {
    methodConfig: [{ name: [{}], waitForReady: true }]
}

So my questions are:

  1. How can I test that the Wait-For-Ready option is enabled?
  2. How can I set the Wait-For-Ready option and can I do it via service config?

Upvotes: 1

Views: 45

Answers (1)

murgatroid99
murgatroid99

Reputation: 20297

You can set the waitForReady option in the Metadata constructor:

const metadata = new Metadata({ waitForReady: true});

You can also set it on an existing Metadata object using the setOptions method:

metadata.setOptions({ waitForReady: true});

The metadata.set method sets a metadata value, which has no effect on library behavior.

The waitForReady behavior is not configurable in the service config.


The waitForReady option only has an effect when the client can't connect to a server. Without the option set, if the client can't establish a connection, requests will end with the UNAVAILABLE status. With the option set, requests will wait, and eventually either start communicating with the server or end with the DEADLINE_EXCEEDED status. The error message associated with the DEADLINE_EXCEEDED error will mention "wait_for_ready" if the option is set.

Upvotes: 1

Related Questions