Fix possible deadlock in "stopQuery".