Fix race condition in ConnectionManager.