Skip to content

Commit a83ebd9

Browse files
authored
Merge pull request #210 from Shopify/fix-zk-leader-serves-bug
zk wait until StateHasSession
2 parents 2aee1cb + b4bf4ad commit a83ebd9

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

go/vt/topo/zk2topo/zk_conn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ func dialZk(ctx context.Context, addr string) (*zk.Conn, <-chan zk.Event, error)
406406
return nil, nil, ctx.Err()
407407
case event := <-session:
408408
switch event.State {
409-
case zk.StateConnected:
409+
case zk.StateHasSession:
410410
// success
411411
return zconn, session, nil
412412

go/vt/topo/zk2topo/zk_conn_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,19 @@ func TestZkConnClosedOnDisconnect(t *testing.T) {
6060

6161
require.Equal(t, zk.StateDisconnected, oldConn.State(), "Connection is not in disconnected state")
6262
}
63+
64+
func TestDialWaitsForSession(t *testing.T) {
65+
zkd, serverAddr := zkctl.StartLocalZk(testfiles.GoVtTopoZk2topoZkID, testfiles.GoVtTopoZk2topoPort)
66+
defer zkd.Teardown()
67+
68+
conn, _, err := dialZk(context.Background(), serverAddr)
69+
if err != nil {
70+
t.Fatalf("dialZk failed: %v", err)
71+
}
72+
73+
defer conn.Close()
74+
75+
if conn.State() != zk.StateHasSession {
76+
t.Fatalf("zk connection not in StateHasSession: %v", conn.State())
77+
}
78+
}

0 commit comments

Comments
 (0)