So far, the implementation of CassFuture caused deadlock when the only thread called cass_future_wait(). This happened because the thread went asleep on a Condvar until the future is resolved, but there were no
other executors that would resolve the future.
Although a runtime with no worker threads is not recommended for production usage, it is helpful e.g. for debugging (as it makes execution serialised). Therefore, we fix the problem by changing the way the thread waits for the future's result: instead of sleeping while the future is not yet resolved, it calls runtime.block_on(fut), which makes
it the executor of that future.
This not only fixes the problem, but possibly boosts efficiency.
More specifically, it saves a sleep and a wakeup in the case of having a non-empty worker thread pool (the main thread does not wake a worker, falls asleep until the worker thread resolves the future and gets woken up in the end, but instead simply does the work by itself).
To test that the changes did solve the problem, change RUNTIME in lib.rs into a "current thread" variant:
from:
So far, the implementation of CassFuture caused deadlock when the only thread called
cass_future_wait()
. This happened because the thread went asleep on a Condvar until the future is resolved, but there were no other executors that would resolve the future. Although a runtime with no worker threads is not recommended for production usage, it is helpful e.g. for debugging (as it makes execution serialised). Therefore, we fix the problem by changing the way the thread waits for the future's result: instead of sleeping while the future is not yet resolved, it calls runtime.block_on(fut), which makes it the executor of that future. This not only fixes the problem, but possibly boosts efficiency. More specifically, it saves a sleep and a wakeup in the case of having a non-empty worker thread pool (the main thread does not wake a worker, falls asleep until the worker thread resolves the future and gets woken up in the end, but instead simply does the work by itself).To test that the changes did solve the problem, change
RUNTIME
inlib.rs
into a "current thread" variant: from:into:
Pre-review checklist
[ ] I have enabled appropriate tests in.github/workflows/build.yml
ingtest_filter
.[ ] I have enabled appropriate tests in.github/workflows/cassandra.yml
ingtest_filter
.