Skip to content

Commit d09e2f2

Browse files
committed
[FAB-8061] Update grpc-go to latest version
Update to grpc-go 1.10.0 We were several releases behind and there were changes in behavior and some APIs which required tweaking production and test code Change-Id: I86bc6cd170b5a07777c11db485bb86fdc73e495a Signed-off-by: Gari Singh <gari.r.singh@gmail.com>
1 parent 7ad239c commit d09e2f2

File tree

101 files changed

+8101
-3317
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+8101
-3317
lines changed

Gopkg.lock

+18-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ required = [
140140

141141
[[constraint]]
142142
name = "google.golang.org/grpc"
143-
version = "=1.5.2"
143+
version = "=1.10.0"
144144

145145
[[constraint]]
146146
name = "gopkg.in/alecthomas/kingpin.v2"

core/chaincode/accesscontrol/access_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func TestAccessControl(t *testing.T) {
172172
// Create an attacker without a TLS certificate
173173
_, err = newClient(t, 7052, nil, ca.CertBytes())
174174
assert.Error(t, err)
175-
assert.Contains(t, err.Error(), "tls: bad certificate")
175+
assert.Contains(t, err.Error(), "context deadline exceeded")
176176

177177
// Create an attacker with its own TLS certificate
178178
maliciousCA, _ := NewCA()
@@ -181,7 +181,7 @@ func TestAccessControl(t *testing.T) {
181181
assert.NoError(t, err)
182182
_, err = newClient(t, 7052, &cert, ca.CertBytes())
183183
assert.Error(t, err)
184-
assert.Contains(t, err.Error(), "tls: bad certificate")
184+
assert.Contains(t, err.Error(), "context deadline exceeded")
185185

186186
// Create a chaincode for example01 that tries to impersonate example02
187187
kp, err := auth.Generate("example01")

core/chaincode/accesscontrol/ca_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,5 @@ func TestTLSCA(t *testing.T) {
8989
assert.NoError(t, err)
9090
err = probeTLS(kp)
9191
assert.Error(t, err)
92-
assert.Contains(t, err.Error(), "tls: bad certificate")
92+
assert.Contains(t, err.Error(), "context deadline exceeded")
9393
}

core/comm/client_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func TestNewConnection(t *testing.T) {
220220
serverTLS: &tls.Config{
221221
Certificates: []tls.Certificate{testServerCert}},
222222
success: false,
223-
errorMsg: "certificate signed by unknown authority",
223+
errorMsg: "context deadline exceeded",
224224
},
225225
{
226226
name: "client TLS / server TLS missing client cert",
@@ -237,7 +237,7 @@ func TestNewConnection(t *testing.T) {
237237
Certificates: []tls.Certificate{testServerCert},
238238
ClientAuth: tls.RequireAndVerifyClientCert},
239239
success: false,
240-
errorMsg: "bad certificate",
240+
errorMsg: "context deadline exceeded",
241241
},
242242
{
243243
name: "client TLS / server TLS client cert",

core/comm/config.go

+5
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,15 @@ var (
4040
tls.TLS_RSA_WITH_AES_128_GCM_SHA256,
4141
tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
4242
}
43+
// default connection timeout
44+
DefaultConnectionTimeout = 5 * time.Second
4345
)
4446

4547
// ServerConfig defines the parameters for configuring a GRPCServer instance
4648
type ServerConfig struct {
49+
// ConnectionTimeout specifies the timeout for connection establishment
50+
// for all new connections
51+
ConnectionTimeout time.Duration
4752
// SecOpts defines the security parameters
4853
SecOpts *SecureOptions
4954
// KaOpts defines the keepalive parameters

core/comm/config_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
)
1515

1616
func TestConfig(t *testing.T) {
17+
t.Parallel()
1718
// check the defaults
1819
assert.EqualValues(t, maxRecvMsgSize, MaxRecvMsgSize())
1920
assert.EqualValues(t, maxSendMsgSize, MaxSendMsgSize())

core/comm/connection_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ func newServer(org string, port int) *srv {
282282
panic(fmt.Errorf("Failed listening on port %d: %v", port, err))
283283
}
284284
gSrv, err := NewGRPCServerFromListener(l, ServerConfig{
285+
ConnectionTimeout: 250 * time.Millisecond,
285286
SecOpts: &SecureOptions{
286287
Certificate: certs["server.crt"],
287288
Key: certs["server.key"],
@@ -338,14 +339,14 @@ func testInvoke(t *testing.T, channelID string, s *srv, shouldSucceed bool) {
338339
assert.NoError(t, err)
339340
endpoint := fmt.Sprintf("localhost:%d", s.port)
340341
ctx := context.Background()
341-
ctx, _ = context.WithTimeout(ctx, time.Second*3)
342+
ctx, _ = context.WithTimeout(ctx, 1*time.Second)
342343
conn, err := grpc.DialContext(ctx, endpoint, grpc.WithTransportCredentials(creds), grpc.WithBlock())
343344
if shouldSucceed {
344345
assert.NoError(t, err)
345346
defer conn.Close()
346347
} else {
347348
assert.Error(t, err)
348-
assert.Contains(t, err.Error(), "certificate signed by unknown authority")
349+
assert.Contains(t, err.Error(), "context deadline exceeded")
349350
return
350351
}
351352
client := testpb.NewTestServiceClient(conn)

core/comm/creds_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
)
1818

1919
func TestCreds(t *testing.T) {
20+
t.Parallel()
2021
var creds credentials.TransportCredentials
2122
creds = comm.NewServerTransportCredentials(&tls.Config{})
2223
_, _, err := creds.ClientHandshake(nil, "", nil)

core/comm/producer_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ import (
1616
)
1717

1818
func TestEmptyEndpoints(t *testing.T) {
19+
t.Parallel()
1920
noopFactory := func(endpoint string) (*grpc.ClientConn, error) {
2021
return nil, nil
2122
}
2223
assert.Nil(t, NewConnectionProducer(noopFactory, []string{}))
2324
}
2425

2526
func TestConnFailures(t *testing.T) {
27+
t.Parallel()
2628
conn2Endpoint := make(map[string]string)
2729
shouldConnFail := map[string]bool{
2830
"a": true,
@@ -70,6 +72,7 @@ func TestConnFailures(t *testing.T) {
7072
}
7173

7274
func TestUpdateEndpoints(t *testing.T) {
75+
t.Parallel()
7376
conn2Endpoint := make(map[string]string)
7477
connFactory := func(endpoint string) (*grpc.ClientConn, error) {
7578
conn := &grpc.ClientConn{}
@@ -97,6 +100,7 @@ func TestUpdateEndpoints(t *testing.T) {
97100
}
98101

99102
func TestDisableEndpoint(t *testing.T) {
103+
t.Parallel()
100104
orgEndpointDisableInterval := EndpointDisableInterval
101105
EndpointDisableInterval = time.Millisecond * 100
102106
defer func() { EndpointDisableInterval = orgEndpointDisableInterval }()

core/comm/server.go

+7
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ func NewGRPCServerFromListener(listener net.Listener, serverConfig ServerConfig)
122122
serverOpts = append(serverOpts, grpc.MaxRecvMsgSize(MaxRecvMsgSize()))
123123
// set the keepalive options
124124
serverOpts = append(serverOpts, ServerKeepaliveOptions(serverConfig.KaOpts)...)
125+
// set connection timeout
126+
if serverConfig.ConnectionTimeout <= 0 {
127+
serverConfig.ConnectionTimeout = DefaultConnectionTimeout
128+
}
129+
serverOpts = append(
130+
serverOpts,
131+
grpc.ConnectionTimeout(serverConfig.ConnectionTimeout))
125132

126133
grpcServer.server = grpc.NewServer(serverOpts...)
127134

core/comm/server_test.go

+36-18
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ func (tss *testServiceServer) EmptyCall(context.Context, *testpb.Empty) (*testpb
111111
func invokeEmptyCall(address string, dialOptions []grpc.DialOption) (*testpb.Empty, error) {
112112

113113
//add DialOptions
114-
dialOptions = append(dialOptions, grpc.WithBlock())
114+
dialOptions = append(
115+
dialOptions,
116+
grpc.WithDefaultCallOptions(grpc.FailFast(true)),
117+
grpc.FailOnNonTempDialError(true),
118+
grpc.WithBlock())
115119
ctx := context.Background()
116120
ctx, _ = context.WithTimeout(ctx, timeout)
117121
//create GRPC client conn
@@ -194,6 +198,7 @@ func (org *testOrg) testServers(port int, clientRootCAs [][]byte) []testServer {
194198
testServer := testServer{
195199
fmt.Sprintf("localhost:%d", port+i),
196200
comm.ServerConfig{
201+
ConnectionTimeout: 250 * time.Millisecond,
197202
SecOpts: &comm.SecureOptions{
198203
UseTLS: true,
199204
Certificate: serverCert.certPEM,
@@ -575,6 +580,7 @@ func TestNewSecureGRPCServer(t *testing.T) {
575580
t.Parallel()
576581
testAddress := "localhost:9055"
577582
srv, err := comm.NewGRPCServer(testAddress, comm.ServerConfig{
583+
ConnectionTimeout: 250 * time.Millisecond,
578584
SecOpts: &comm.SecureOptions{
579585
UseTLS: true,
580586
Certificate: []byte(selfSignedCertPEM),
@@ -633,18 +639,22 @@ func TestNewSecureGRPCServer(t *testing.T) {
633639
t.Log("GRPC client successfully invoked the EmptyCall service: " + testAddress)
634640
}
635641

636-
// ensure that TLS 1.2 in required / enforced
637-
for _, tlsVersion := range []uint16{tls.VersionSSL30, tls.VersionTLS10, tls.VersionTLS11} {
638-
_, err = invokeEmptyCall(testAddress,
639-
[]grpc.DialOption{grpc.WithTransportCredentials(
640-
credentials.NewTLS(&tls.Config{
641-
RootCAs: certPool,
642-
MinVersion: tlsVersion,
643-
MaxVersion: tlsVersion,
644-
}))})
645-
t.Logf("TLSVersion [%d] failed with [%s]", tlsVersion, err)
646-
assert.Error(t, err, "Should not have been able to connect with TLS version < 1.2")
647-
assert.Contains(t, err.Error(), "protocol version not supported")
642+
tlsVersions := []string{"SSL30", "TLS10", "TLS11"}
643+
for counter, tlsVersion := range []uint16{tls.VersionSSL30, tls.VersionTLS10, tls.VersionTLS11} {
644+
tlsVersion := tlsVersion
645+
t.Run(tlsVersions[counter], func(t *testing.T) {
646+
t.Parallel()
647+
_, err = invokeEmptyCall(testAddress,
648+
[]grpc.DialOption{grpc.WithTransportCredentials(
649+
credentials.NewTLS(&tls.Config{
650+
RootCAs: certPool,
651+
MinVersion: tlsVersion,
652+
MaxVersion: tlsVersion,
653+
}))})
654+
t.Logf("TLSVersion [%d] failed with [%s]", tlsVersion, err)
655+
assert.Error(t, err, "Should not have been able to connect with TLS version < 1.2")
656+
assert.Contains(t, err.Error(), "context deadline exceeded")
657+
})
648658
}
649659
}
650660

@@ -923,7 +933,11 @@ func runMutualAuth(t *testing.T, servers []testServer, trustedClients, unTrusted
923933
//loop through all the untrusted clients
924934
for k := 0; k < len(unTrustedClients); k++ {
925935
//invoke the EmptyCall service
926-
_, err = invokeEmptyCall(servers[i].address, []grpc.DialOption{grpc.WithTransportCredentials(credentials.NewTLS(unTrustedClients[k]))})
936+
_, err = invokeEmptyCall(
937+
servers[i].address,
938+
[]grpc.DialOption{
939+
grpc.WithTransportCredentials(
940+
credentials.NewTLS(unTrustedClients[k]))})
927941
//we expect failure from untrusted clients
928942
if err != nil {
929943
t.Logf("Untrusted client%d was correctly rejected by %s", k, servers[i].address)
@@ -1413,8 +1427,12 @@ func TestKeepaliveClientResponse(t *testing.T) {
14131427
defer srv.Stop()
14141428

14151429
// test that connection does not close with response to ping
1416-
clientTransport, err := transport.NewClientTransport(context.Background(),
1417-
transport.TargetInfo{Addr: testAddress}, transport.ConnectOptions{})
1430+
clientTransport, err := transport.NewClientTransport(
1431+
context.Background(),
1432+
context.Background(),
1433+
transport.TargetInfo{Addr: testAddress},
1434+
transport.ConnectOptions{},
1435+
func() {})
14181436
assert.NoError(t, err, "Unexpected error creating client transport")
14191437
defer clientTransport.Close()
14201438
// sleep past keepalive timeout
@@ -1469,7 +1487,7 @@ func TestUpdateTLSCert(t *testing.T) {
14691487
// bootstrap TLS certificate has a SAN of "notlocalhost" so it should fail
14701488
err = probeServer()
14711489
assert.Error(t, err)
1472-
assert.Contains(t, err.Error(), "certificate is valid for notlocalhost.org1.example.com, notlocalhost, not localhost")
1490+
assert.Contains(t, err.Error(), "context deadline exceeded")
14731491

14741492
// new TLS certificate has a SAN of "localhost" so it should succeed
14751493
certPath := filepath.Join("testdata", "dynamic_cert_update", "localhost", "server.crt")
@@ -1488,7 +1506,7 @@ func TestUpdateTLSCert(t *testing.T) {
14881506
srv.SetServerCertificate(tlsCert)
14891507
err = probeServer()
14901508
assert.Error(t, err)
1491-
assert.Contains(t, err.Error(), "certificate is valid for notlocalhost.org1.example.com, notlocalhost, not localhost")
1509+
assert.Contains(t, err.Error(), "context deadline exceeded")
14921510
}
14931511

14941512
func TestCipherSuites(t *testing.T) {

core/comm/util_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
)
2929

3030
func TestExtractCertificateHashFromContext(t *testing.T) {
31+
t.Parallel()
3132
assert.Nil(t, comm.ExtractCertificateHashFromContext(context.Background()))
3233

3334
p := &peer.Peer{}
@@ -61,12 +62,14 @@ func (*nonTLSConnection) AuthType() string {
6162
}
6263

6364
func TestBindingInspectorBadInit(t *testing.T) {
65+
t.Parallel()
6466
assert.Panics(t, func() {
6567
comm.NewBindingInspector(false, nil)
6668
})
6769
}
6870

6971
func TestNoopBindingInspector(t *testing.T) {
72+
t.Parallel()
7073
extract := func(msg proto.Message) []byte {
7174
return nil
7275
}
@@ -77,6 +80,7 @@ func TestNoopBindingInspector(t *testing.T) {
7780
}
7881

7982
func TestBindingInspector(t *testing.T) {
83+
t.Parallel()
8084
testAddress := "localhost:25000"
8185
extract := func(msg proto.Message) []byte {
8286
env, isEnvelope := msg.(*common.Envelope)
@@ -152,6 +156,7 @@ func (is *inspectingServer) inspect(envelope *common.Envelope) error {
152156

153157
func newInspectingServer(addr string, inspector comm.BindingInspector) *inspectingServer {
154158
srv, err := comm.NewGRPCServer(addr, comm.ServerConfig{
159+
ConnectionTimeout: 250 * time.Millisecond,
155160
SecOpts: &comm.SecureOptions{
156161
UseTLS: true,
157162
Certificate: []byte(selfSignedCertPEM),

0 commit comments

Comments
 (0)