Added a lock to fix a multithreading issue when starting up under stress