-
Notifications
You must be signed in to change notification settings - Fork 36
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
Encapsulating choices of context and dial options in a library is an anti-pattern. That should be driven from top level. Lets not do that here. #446
Conversation
…anti-pattern. That should be driven from top level. Lets not do that here. Signed-off-by: Ed Warnicke <[email protected]>
// This function may be useful in the environments when not guarantee that the server socket is immediately provided. | ||
func DialContextTimeout(ctx context.Context, target string, duration time.Duration, opts ...grpc.DialOption) (conn *grpc.ClientConn, err error) { | ||
timeout := time.After(duration) | ||
for { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Among other issues... this forces any DialContext to block until success. Since most uses of DialContext should not do that... this is inappropriate in a drop in replacement for DialContext.
// DialContext tries to create a client connection to the given target during 1 minute. | ||
// This function may be useful in the environments when not guarantee that the server socket is immediately provided. | ||
func DialContext(ctx context.Context, target string, opts ...grpc.DialOption) (*grpc.ClientConn, error) { | ||
return DialContextTimeout(ctx, target, time.Minute, opts...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Timeout choices should come from outside... from the main or from the context of a call... not from a library.
@edwarnicke ok, How then we should handle a case when we are using unix based client/server + k8s slow file mount API? Should we add in each cmd application this removed waiting? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested different setups and here is my result:
Setup
- Deploy spire
- Deploy any unix based grpc server with TLS
- Deploy grpc client with TLS for the server from step 2.
Testing
Using grpc.WaitForReady
I've tried to replace grpcuitls.DialContext to grpc.DialContext and added grpc.WaitFoReady(true) on first call. In this case, 5/10 my tries client's POD freezes on the first API call. So I think we can not use grpc.WaitFoReady(true) in k8s with unix based connections
Using grpc.Withblock
I've tried to replace grpcuitls.DialContext to grpc.DialContext and added grpc.Block() into Dial function. This variant working correctly
Conclution
We can remove this dial function and use grpc.WithBlock() option in each our grpc client.
…k@master networkservicemesh/sdk#446 networkservicemesh/sdk PR link: networkservicemesh/sdk#446 networkservicemesh/sdk commit message: commit 1be3f50d7da793ed1ff063c88e26e9c94bdfd44c Author: Ed Warnicke <[email protected]> Date: Fri Aug 21 01:55:31 2020 -0500 Encapsulating choices of context and dial options in a library is an anti-pattern. (#446) That should be driven from top level. Lets not do that here. Signed-off-by: Ed Warnicke <[email protected]> Signed-off-by: NSMBot <[email protected]>
…k@master networkservicemesh/sdk#446 networkservicemesh/sdk PR link: networkservicemesh/sdk#446 networkservicemesh/sdk commit message: commit 1be3f50d7da793ed1ff063c88e26e9c94bdfd44c Author: Ed Warnicke <[email protected]> Date: Fri Aug 21 01:55:31 2020 -0500 Encapsulating choices of context and dial options in a library is an anti-pattern. (#446) That should be driven from top level. Lets not do that here. Signed-off-by: Ed Warnicke <[email protected]> Signed-off-by: NSMBot <[email protected]>
…k@master networkservicemesh/sdk#446 networkservicemesh/sdk PR link: networkservicemesh/sdk#446 networkservicemesh/sdk commit message: commit 1be3f50d7da793ed1ff063c88e26e9c94bdfd44c Author: Ed Warnicke <[email protected]> Date: Fri Aug 21 01:55:31 2020 -0500 Encapsulating choices of context and dial options in a library is an anti-pattern. (#446) That should be driven from top level. Lets not do that here. Signed-off-by: Ed Warnicke <[email protected]> Signed-off-by: NSMBot <[email protected]>
…k@master networkservicemesh/sdk#446 networkservicemesh/sdk PR link: networkservicemesh/sdk#446 networkservicemesh/sdk commit message: commit 1be3f50d7da793ed1ff063c88e26e9c94bdfd44c Author: Ed Warnicke <[email protected]> Date: Fri Aug 21 01:55:31 2020 -0500 Encapsulating choices of context and dial options in a library is an anti-pattern. (#446) That should be driven from top level. Lets not do that here. Signed-off-by: Ed Warnicke <[email protected]> Signed-off-by: NSMBot <[email protected]>
…k@master networkservicemesh/sdk#446 networkservicemesh/sdk PR link: networkservicemesh/sdk#446 networkservicemesh/sdk commit message: commit 1be3f50d7da793ed1ff063c88e26e9c94bdfd44c Author: Ed Warnicke <[email protected]> Date: Fri Aug 21 01:55:31 2020 -0500 Encapsulating choices of context and dial options in a library is an anti-pattern. (#446) That should be driven from top level. Lets not do that here. Signed-off-by: Ed Warnicke <[email protected]> Signed-off-by: NSMBot <[email protected]>
No description provided.