Skip to content

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

@GuillaumeDua

Description

@GuillaumeDua

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions