Fix a deadlock in the scheduler