If watches are cancelled on timeout, the NativeFuture.cancel() gets called, but the future itself is not disposed, so after 10000 watch cancellations, this will cause the connection to fail creating watches.
Sample code:
public static void main(String[] args) throws Exception {
var db = FDB.selectAPIVersion(710)
.open();
AtomicLong c = new AtomicLong();
while (true) {
var watch = db.run(tr -> {
return tr.watch("foo".getBytes());
});
watch.orTimeout(1, TimeUnit.MILLISECONDS)
.exceptionally(e -> {
if(e instanceof TimeoutException) {
return null;
}
throw new RuntimeException(e);
})
.get();
// ((AutoCloseable) watch).close(); // <- without this line, this will fail after 10k loops.
System.out.println("Watch no " + c.incrementAndGet());
}
}
Shouldn’t the NativeFuture.cancel also call Future_dispose(ptr);
? Now the only way is to cast the CompletableFuture to an AutoClosable and manually call close() on cancel.