Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
daniil-berg opened this issue Oct 14, 2023 · 0 comments
Labels
bug Something isn't working race condition Concurrency may lead to undesirable execution

Comments

@daniil-berg
Copy link
Owner

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.

@daniil-berg daniil-berg added bug Something isn't working race condition Concurrency may lead to undesirable execution labels Oct 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working race condition Concurrency may lead to undesirable execution
Projects
None yet
Development

No branches or pull requests

1 participant