Fix race condition introduced in #386