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

Expose option to eagerly create connection #2677

Closed
carl-mastrangelo opened this issue Mar 9, 2019 · 9 comments
Closed

Expose option to eagerly create connection #2677

carl-mastrangelo opened this issue Mar 9, 2019 · 9 comments

Comments

@carl-mastrangelo
Copy link
Contributor

There doesn't seem to be a way to eagerly connect to a target address. My use case:

  1. Create gRPC ClientConn
  2. Do some work
  3. Try to send an RPC using results from 2
  4. RPC fails because the address is from 1 is wrong.

gRPC Java exposes this through the channel state API, but for Go I expect this to be a DialOption.

@lyuxuan
Copy link
Contributor

lyuxuan commented Mar 11, 2019

Use grpc.WithBlock() to block until a connection is established.

@dfawley
Copy link
Member

dfawley commented Mar 11, 2019

You also will want to use grpc.FailOnNonTempDialError(true) so you don't wait until the context expires to determine there was a persistent connection error.

Similar to Java, Go also have a connectivity state API:

https://godoc.org/google.golang.org/grpc#ClientConn.GetState
https://godoc.org/google.golang.org/grpc#ClientConn.WaitForStateChange

@carl-mastrangelo
Copy link
Contributor Author

@dfawley I looked at those, but neither say that they have any effects. GetState doesn't say that the state will ever go towards READY. WaitForStateChange doesn't imply it kick the ClientConn towards READY, only that if it does change, it will eventually run. Neither move the ClientConn towards the state I want.

@lyuxuan Thanks! it would be very helpful if WithBlock had some synonyms in that doc. I ctrl-F'd through the doc for "Eager" and "ready", but neither came up.

@dfawley
Copy link
Member

dfawley commented Mar 11, 2019

@carl-mastrangelo Go doesn't currently have the concept of idleness - it starts in Connecting, so these functions don't have side-effects.

@carl-mastrangelo
Copy link
Contributor Author

@dfawley Then how does pick first work? Doesn't that LB policy imply that connections are lazily created?

@dfawley
Copy link
Member

dfawley commented Mar 11, 2019

The balancer doesn't matter - all ClientConns always start in Connecting. The resolver returns addresses, the balancer gets them and then it immediately tries to connect to the ones that will be used. Nothing in this process waits for an RPC. We also eagerly reconnect, even after a GOAWAY, which is a known, meaningful difference between Go & other languages. #1786

@carl-mastrangelo
Copy link
Contributor Author

Ok so what you are saying is Dial and DialContext are always eager. WithBlock still doesn't seem to be what I want because:

... blocks until the underlying connection is up

Which connection is this? In the load balanced case there may be multiple. Does it wait until failure, or success, or either?

#1786

It would be great if this could be prioritized. It was confusing to me that Dial would return an error type, but not block. I think NewClient could return an $CLIENT, without an error param, making it clear that no connection has been established.

@dfawley
Copy link
Member

dfawley commented Mar 12, 2019

@carl-mastrangelo WithBlock blocks until the ClientConn is Ready, which is whenever the LB policy decides, but that's typically when a single connection itself becomes Ready. It blocks until the deadline is reached, or until there is a non-termporary error if you also use FailOnNonTempDialError.

If you don't want to block, you can use the connectivity state API instead.

It would be great if this could be prioritized.

I agree, but we have a few things in front of it right now. It will probably be a couple more quarters before it happens at this rate, assuming no new things come in.

@dfawley
Copy link
Member

dfawley commented Mar 14, 2019

We always eagerly create the connection. When we support NewClient, we will update the connectivity state API to allow for this (#1786).

@dfawley dfawley closed this as completed Mar 14, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants