Github user ilooner commented on the issue:
@vrozov Thanks for catching this, I believe you are right.
hasClouseoutThread guarantees innerNext and close won't be called concurrently.
However, I still believe innerNext and receivingFragmentFinished could be
called concurrently, since the ControlMessageHandler thread executes
recievingFragmentFinished. Additionally in rare cases where a limit query is
cancelled recievingFragmentFinished and close could be called concurrently as
well. While reflecting on your comments I also saw another issue where the root
could be blocked on a next call but a Finished event would not cause root to
In light of all of this I actually think the **synchronized** is not
sufficient. We will have to have some way to interrupt the execution of the
root when we received a finish signal and only close out the resources after
receivingFragmentFinished has been called. Similarly if we receive a finish
signal we should ignore any cancellation requests instead of trying to cancel
and finish simultaneously and vice versa.
I will rework the solution to address these issues and let you know when I
have an update.