client: Revert dialWithGlobalOption (#6012)

This commit is contained in:
Zach Reyes 2023-02-08 17:02:17 -05:00 committed by GitHub
parent d655f404da
commit ceb3f07190
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 2 additions and 31 deletions

View File

@ -133,10 +133,6 @@ func (dcs *defaultConfigSelector) SelectConfig(rpcInfo iresolver.RPCInfo) (*ires
// https://github.com/grpc/grpc/blob/master/doc/naming.md.
// e.g. to use dns resolver, a "dns:///" prefix should be applied to the target.
func DialContext(ctx context.Context, target string, opts ...DialOption) (conn *ClientConn, err error) {
return dialWithGlobalOptions(ctx, target, false, opts...)
}
func dialWithGlobalOptions(ctx context.Context, target string, disableGlobalOptions bool, opts ...DialOption) (conn *ClientConn, err error) {
cc := &ClientConn{
target: target,
csMgr: &connectivityStateManager{},
@ -150,10 +146,8 @@ func dialWithGlobalOptions(ctx context.Context, target string, disableGlobalOpti
cc.safeConfigSelector.UpdateConfigSelector(&defaultConfigSelector{nil})
cc.ctx, cc.cancel = context.WithCancel(context.Background())
if !disableGlobalOptions {
for _, opt := range globalDialOptions {
opt.apply(&cc.dopts)
}
for _, opt := range globalDialOptions {
opt.apply(&cc.dopts)
}
for _, opt := range opts {

View File

@ -19,7 +19,6 @@
package grpc
import (
"context"
"strings"
"testing"
@ -59,24 +58,6 @@ func (s) TestAddGlobalDialOptions(t *testing.T) {
}
}
// TestDisableGlobalOptions tests dialing with a bit that disables global
// options. Dialing with this bit set should not pick up global options.
func (s) TestDisableGlobalOptions(t *testing.T) {
// Set transport credentials as a global option.
internal.AddGlobalDialOptions.(func(opt ...DialOption))(WithTransportCredentials(insecure.NewCredentials()))
// Dial with disable global options set to true. This Dial should fail due
// to the global dial options with credentials not being picked up due to it
// being disabled.
if _, err := internal.DialWithGlobalOptions.(func(context.Context, string, bool, ...DialOption) (*ClientConn, error))(context.Background(), "fake", true); err == nil {
t.Fatalf("Dialing without a credential did not fail")
} else {
if !strings.Contains(err.Error(), "no transport security set") {
t.Fatalf("Dialing failed with unexpected error: %v", err)
}
}
internal.ClearGlobalDialOptions()
}
func (s) TestAddGlobalServerOptions(t *testing.T) {
const maxRecvSize = 998765
// Set and check the ServerOptions

View File

@ -43,7 +43,6 @@ func init() {
internal.ClearGlobalDialOptions = func() {
globalDialOptions = nil
}
internal.DialWithGlobalOptions = dialWithGlobalOptions
internal.WithBinaryLogger = withBinaryLogger
internal.JoinDialOptions = newJoinDialOption
}

View File

@ -29,9 +29,6 @@ import (
)
var (
// DialWithGlobalOptions dials with a knob on whether to disable global dial
// options (set via AddGlobalDialOptions).
DialWithGlobalOptions interface{} // func (context.Context, string, bool, ...DialOption) (*ClientConn, error)
// WithHealthCheckFunc is set by dialoptions.go
WithHealthCheckFunc interface{} // func (HealthChecker) DialOption
// HealthCheckFunc is used to provide client-side LB channel health checking