zookeeper-cpp icon indicating copy to clipboard operation
zookeeper-cpp copied to clipboard

Connection loss management

Open GuillaumeDua opened this issue 4 years ago • 0 comments

Idea : zk::connection should provide a way to reconnect after a connection is loss,
as well as an atomic state

Considering the following example :

zk::connection con = zk::connection::connection("zk://addr:port/?opts");

// somewhere else ...

switch (con->state())
{  // handle some connection loss cases
   case zk::state::closed: [[fallthrough]];
   case zk::state::expired_session:
   {
	reset_connection(); // smthg like `con = zk::connection::connection("zk://addr:port/?opts");`
	break;
   }
   default:
	break;
}

In the sample above, the issue is the switch/case is error-prone, as erasing con content may result in invalid con->state() read in a concurrent context.
This force the user to create some blocking operation using memory barriers and perhaps condition_variales, to ensure no wrong states are evaluated during connection reset.

GuillaumeDua avatar Oct 26 '20 15:10 GuillaumeDua