Fixing internal state corruption cased by task schedulers