oliora/ppconsul

Interrupt blocking query to Key-Value storage

jgornowich opened this issue · 2 comments

I have an application that uses a separate thread to watch a KV item's modification by using the block_for parameter with the kv.items(). The timeout is set to be greater than 1 minute. My issue is that when the application receives a signal to terminate (SIGINT) it hangs on the join() for this thread until the KV blocking query timeout is hit.

I don't really want to decrease the blocking query time down to the 1 second range as I don't really want this thread spinning constantly for no reason. I believe my question/issue is related to an older issue, #9.
Any suggestions on how to do this differently or how I can make a PR for additional capability would be great.

There are two possible ways to fix it. I'll describe them below.

First way is to add a cURL callback function which can tell cURL that the on-going request should be interrupted. This is done via CURLOPT_XFERINFOFUNCTION callback. New function ppconsul::Consul::abort() should be added which will abort all ongoing request on this Consul object.
This solution is simple but it almost only serves the purpose of timely shutdown.

The other way would be to implement an async interface to perform Consul requests. It's questionable whether it should be based on std::future or on client provided completion handler (or even both). This is definitely more work than the first approach but it will bring all the freedom of async API.

I'm fine with either way but if you'd like to go with the async API then we need to discuss its design first. Adding callback is much less intrusive so no upfront discussion is needed unless you want it.

UPDATED

It’s supported now (in the simplest way but still) so closing the issue.