fix possible race condition in scheduler