Fix race condition from commit 099cd1ab9189