Consistent with what @mateiz said, I think it would be better to have "delaySchedule" on all the time (so if new executors come up, we always add them to the tasks' locality lists).  I think this line should be the original version though (just "if (!hadAliveLocations)") -- otherwise if a task really doesn't have any alive locations (and no more are going to  be added in the future), the task will be stuck waiting to be scheduled until the locality wait threshold expires, which could be a long time.