I think this is a race condition. I just raised another ticket for this.
ZOOKEEPER-800 zoo_add_auth should return ZINVALIDSTATE if
2941 // the connection is closed.
2942 if (zoo_state(zh) == 0)
2943 return ZINVALIDSTATE;
When we initialize we assign zk->state=0 and here we check if its 0 return ZKINVALIDSTATE.
So in my case: where i am trying to addAuth right after zookeeper_init(), it sometime returns me ZKINVALIDSTATE (as the state might have not changed to CONNECTING), where as i would expect it to queue the request for me (as is done in the java client)
The problem might be that we are using 0 for both CLOSED and UNINITIALIZED state.