add server state mutex to avoid state race condition