Browse Source

clientv3/integration: fix race condition from closing channel

Go 1.11 now marks len(channel) over being-closed channel
as racey operation, fix tests by receiving from channel first
and then check the length of channel.

```
WARNING: DATA RACE
Write at 0x00c000e872c0 by goroutine 198:
  runtime.closechan()
      /usr/local/go/src/runtime/chan.go:327 +0x0
  go.etcd.io/etcd/clientv3.(*lessor).closeRequireLeader()
      /Users/leegyuho/go/src/go.etcd.io/etcd/clientv3/lease.go:379 +0x748
  go.etcd.io/etcd/clientv3.(*lessor).recvKeepAliveLoop()
      /Users/leegyuho/go/src/go.etcd.io/etcd/clientv3/lease.go:455 +0x3a5

Previous read at 0x00c000e872c0 by goroutine 27:
  go.etcd.io/etcd/clientv3/integration.TestLeaseWithRequireLeader()
      /Users/leegyuho/go/src/go.etcd.io/etcd/clientv3/integration/lease_test.go:828 +0x810
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:827 +0x162
```

Signed-off-by: Gyuho Lee <leegyuho@amazon.com>
Gyuho Lee 7 years ago
parent
commit
839f202195
1 changed files with 4 additions and 1 deletions
  1. 4 1
      clientv3/integration/lease_test.go

+ 4 - 1
clientv3/integration/lease_test.go

@@ -825,8 +825,11 @@ func TestLeaseWithRequireLeader(t *testing.T) {
 	// kaReqLeader may issue multiple requests while waiting for the first
 	// kaReqLeader may issue multiple requests while waiting for the first
 	// response from proxy server; drain any stray keepalive responses
 	// response from proxy server; drain any stray keepalive responses
 	time.Sleep(100 * time.Millisecond)
 	time.Sleep(100 * time.Millisecond)
-	for len(kaReqLeader) > 0 {
+	for {
 		<-kaReqLeader
 		<-kaReqLeader
+		if len(kaReqLeader) == 0 {
+			break
+		}
 	}
 	}
 
 
 	select {
 	select {