Kafka broker re-registers itself in zookeeper every time handleNewSession() callback is invoked.
Now imagine the following sequence of events.
1) Zookeeper session reestablishes. handleNewSession() callback is queued by the zkClient, but not invoked yet.
2) Zookeeper session reestablishes again, queueing callback second time.
3) First callback is invoked, creating /broker/[id] ephemeral path.
4) Second callback is invoked and it tries to create /broker/[id] path using createEphemeralPathExpectConflictHandleZKBug() function. But the path is already exists, so createEphemeralPathExpectConflictHandleZKBug() is getting stuck in the infinite loop.
Seems like controller election code have the same issue.
I'am able to reproduce this issue on the 0.8.1 branch from github using the following configs.
Just start kafka and zookeeper and then pause zookeeper several times using Ctrl-Z.