Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Timout should be applied when waiting for connection #114

@timotheecour

Description

@timotheecour

@sztomi @dkozel

void bug() {
  rpc::client c("localhost", port);// assume server not connected
  c.set_timeout(1000);
  // could call c.get_connection_state() to check if it's rpc::client::connection_state::connected but that's brittle and could run into bugs when it gets disconnected right after we check
  auto res = c.call("fun").as<string>(); // hangs instead of timout exception
}

another example is when server disconnects:

void bug() {
  rpc::client c("localhost", port);
  c.set_timeout(1000);
  // could call c.get_connection_state() to check if it's rpc::client::connection_state::connected but that's brittle and could run into bugs when it gets disconnected right after we check
  while(true){
    auto res = c.call("fun").as<string>(); // hangs when server disconnects instead of timout exception
   // maybe sleep  a bit here
  // assume server gets disconnected at some point
  }
}

EDIT: adding a check on get_connection_state doesn't even help because initally state is initial

if(c.get_connection_state()==rpc::client::connection_state::connected){
 // won't get inside here, initially state is `initial`
  auto res = c.call("fun").as<string>();
}

so looks like timeout isnt' currently very useful; any workaround?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions