Skip to content
This repository was archived by the owner on Jul 27, 2023. It is now read-only.

Unable to shut down immediately during a blocking query #307

Closed
ZstringX opened this issue Feb 13, 2018 · 2 comments
Closed

Unable to shut down immediately during a blocking query #307

ZstringX opened this issue Feb 13, 2018 · 2 comments

Comments

@ZstringX
Copy link
Contributor

Consul consul = Consul.builder()
        .withReadTimeoutMillis(5 * 60 * 1000)
        .build();

Thread t = new Thread(() -> {
    Optional<Value> v = consul.keyValueClient().getValue("key");
    BigInteger index = BigInteger.valueOf(v.get().getModifyIndex());
    QueryOptions options = ImmutableQueryOptions.builder()
            .index(index)
            .wait("1m")
            .build();
    System.out.println("before blocking");
    try {
        consul.keyValueClient().getValue("key", options);
    } catch (ConsulException e) {
        // ignore
    }
    System.out.println("after blocking");
});
t.start();

try {
    Thread.sleep(1000);
    consul.destroy();           // not working
    t.interrupt();              // also not working
    t.join();                   // will block until the blocking query ends
} catch (Exception e) {
    e.printStackTrace();
}

The thread will be blocking on socket.read()
Maybe the socket should be manually closed when calling consul.destroy()?

@ZstringX
Copy link
Contributor Author

this should do the trick #308

@yfouquet
Copy link
Collaborator

I've checked and it also works for caches.
Thanks @ZstringX.

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

No branches or pull requests

2 participants