clientv3: don't panic on Get if NewKV is created with a closed client

This commit is contained in:
Anthony Romano 2016-05-31 14:06:05 -07:00
parent 1d88130522
commit a83051d0fc
2 changed files with 28 additions and 1 deletions

View File

@ -309,6 +309,33 @@ func TestKVGetErrConnClosed(t *testing.T) {
}
}
func TestKVNewAfterClose(t *testing.T) {
defer testutil.AfterTest(t)
clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1})
defer clus.Terminate(t)
cli := clus.Client(0)
clus.TakeClient(0)
if err := cli.Close(); err != nil {
t.Fatal(err)
}
donec := make(chan struct{})
go func() {
kv := clientv3.NewKV(cli)
if _, err := kv.Get(context.TODO(), "foo"); err != rpctypes.ErrConnClosed {
t.Fatalf("expected %v, got %v", rpctypes.ErrConnClosed, err)
}
close(donec)
}()
select {
case <-time.After(3 * time.Second):
t.Fatal("kv.Get took too long")
case <-donec:
}
}
func TestKVDeleteRange(t *testing.T) {
defer testutil.AfterTest(t)

View File

@ -90,7 +90,7 @@ func (r *remoteClient) acquire(ctx context.Context) error {
c := r.client.conn
match := r.conn == c
r.mu.Unlock()
if match {
if c != nil && match {
return nil
}
r.client.mu.RUnlock()