Fix race condition with query upload