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

zk::client::connect : cannot abort/timeout/cancel connection attempt #122

Open
GuillaumeDua opened this issue Oct 5, 2020 · 2 comments
Open

Comments

@GuillaumeDua
Copy link

Is there a way to cancel connection ?

For instance, when trying to connect to a Zk server that is not running, how can we abord the connection attempt ?

According to the following snippet,

auto main() -> int
{
	try
	{
		auto client_future = zk::client::connect("zk://127.0.0.1:2181"); // local server which is currently stopped
		using namespace std::chrono_literals;
		const auto wait_result = client_future.wait_for(2s);
		if (wait_result != std::future_status::ready)
		{
			throw std::runtime_error{ "timeout 1" }; // reached, but after throw(),
                                                                                    // the code flow go back to `auto client_future = zk::client::connect("zk://127.0.0.1:2181");`
		}
	}
	catch (const std::runtime_error& error)
	{       // never reached
		std::cerr << "error : " << error.what() << '\n';
	}
	return 0;
@GuillaumeDua
Copy link
Author

Ps : The issue (if an issue it is for you as a library designer), is related to https://en.cppreference.com/w/cpp/thread/future/%7Efuture to me

@GuillaumeDua
Copy link
Author

In my opinion :

auto client = zk::client::connect(/*args...*/)

should be equivalent to :

auto client = zk::client{zk::connection::connect(/*args...*/)}

Having zk::client::connect::get blocking the current thread as long as the client is not connected is not a viable option as we do not have cancelation in the current future implementation.

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

No branches or pull requests

1 participant