Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timout should be applied when waiting for connection #114

Closed
timotheecour opened this issue May 3, 2017 · 4 comments
Closed

Timout should be applied when waiting for connection #114

timotheecour opened this issue May 3, 2017 · 4 comments
Assignees
Labels

Comments

@timotheecour
Copy link

timotheecour commented May 3, 2017

@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?

@sztomi
Copy link
Collaborator

sztomi commented May 3, 2017

Thanks for reporting this. The problem occurs because the client connects asynchronously and waits for the connection at the very first call. I forgot about this waiting and the timeout is not added at that point. I'm going to think about this. I'd like to avoid having a connect function, because part of the API philosophy of rpclib was that if you have an object, it should be useable right away. I can let go of that if I can't find a better way though :)

@sztomi sztomi self-assigned this May 3, 2017
@sztomi sztomi added the bug label May 3, 2017
@sztomi
Copy link
Collaborator

sztomi commented May 3, 2017

OK, this should be a simple fix, but there is no easy workaround. It will be added here:
https://github.com/rpclib/rpclib/blob/master/lib/rpc/client.cc#L166

@sztomi sztomi changed the title timeout doesn't work (ie hangs) when connection to server is lost or inexistant Timout should be applied when waiting for connection May 3, 2017
timotheecour added a commit to timotheecour/rpclib that referenced this issue May 3, 2017
@timotheecour
Copy link
Author

timotheecour commented May 3, 2017

@sztomi PTAL to #118

@sztomi
Copy link
Collaborator

sztomi commented Jul 15, 2017

This was released: https://github.com/rpclib/rpclib/releases/tag/v2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants