It seems that there is a race condition between here and here. In line 67, tasks is accessed without a lock.