Fix race condition in 5dd408071ccb1200e1b53cfa5cf93b67b8dbd69a