Skip to content

Ensure task start is interrupted, if its assigned group or the entire pool is cancelled #4

Description

@daniil-berg

Right now the _start_task method may be subject to a context switch, if the pool size is limited and there is no room for the new task at this point:

await self._enough_room.acquire()

Since the _start_task coroutine is itself scheduled in a task from TaskPool.apply, TaskPool._map, and SimpleTaskPool.start (by proxy of TaskPool._apply_spawner, TaskPool._arg_consumer, and SimpleTaskPool._start_num respectively), this can introduce a race condition:

The _start_task coroutine may still be awaiting the semaphore for enough room, while a cancel was already issued for the group it is assigned to or the entire pool. Cancellation right now only affects tasks in the _tasks_running dictionary. This means the _start_task call may still spawn a new task and add it to _tasks_running after it was supposedly cancelled.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingrace conditionConcurrency may lead to undesirable execution

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions