Old ZK client session watcher event messed up new ZK client session due to ZooKeeper asynchronously closing client session.
The watcher event from old ZK client session can still be sent to ZKRMStateStore after the old ZK client session is closed.
This will cause seriously problem:ZKRMStateStore out of sync with ZooKeeper session.
We only have one ZKRMStateStore but we can have multiple ZK client sessions.
Currently ZKRMStateStore#processWatchEvent doesn't check whether this watcher event is from current session. So the watcher event from old ZK client session which just is closed will still be processed.
For example, If a Disconnected event received from old session after new session is connected, the zkClient will be set to null
Then ZKRMStateStore won't receive SyncConnected event from new session because new session is already in SyncConnected state and it won't send SyncConnected event until it is disconnected and connected again.
Then we will see all the ZKRMStateStore operations fail with IOException "Wait for ZKClient creation timed out" until RM shutdown.
The following code from zookeeper(ClientCnxn#EventThread) show even after receive eventOfDeath, EventThread will still process all the events until waitingEvents queue is empty.