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

Confusing Nanny on_exit callback structure #7321

Open
fjetter opened this issue Nov 16, 2022 · 0 comments · May be fixed by #8611
Open

Confusing Nanny on_exit callback structure #7321

fjetter opened this issue Nov 16, 2022 · 0 comments · May be fixed by #8611
Labels
asyncio hygiene Improve code quality and reduce maintenance overhead

Comments

@fjetter
Copy link
Member

fjetter commented Nov 16, 2022

The Nanny is managing a subprocess in which a Worker is started. If that process exits a cascade of on_exit callbacks are triggered.

The order in which things happen is

  • AsyncProcess._on_exit
    This one is not doing a lot. It sets an event s.t. the process is joinable. Then it triggers another on_exit
  • WorkerProcess._on_exit is just calling WorkerProcess.mark_stopped
  • WorkerProcess.mark_stopped is resetting some state in WorkerProcess and is calling another on_exit
  • Nanny._on_worker_exit_sync is scheduling a coroutine on the loop which is the next on_exit
  • Nanny._on_worker_exit is unregistering the worker from the scheduler and if need be restarts the worker process

This chain of events is not only confusing but also subject to race conditions. Particularly that the final, most relevant on_exit callback is scheduled with a loop.call_soon allows for various race conditions.

These race conditions are currently not a direct issue. Most race conditions are actually buffered by various idempotent implementations of close/start but once we touch this structure, this is getting a bit shaky.

I debugged this during the investigation of #7312 but this chain is not directly causing the issue. This issue is mostly to document the situation.

@fjetter fjetter changed the title Confusing Nanny on_exit callback structure [Draft] Confusing Nanny on_exit callback structure Nov 16, 2022
@fjetter fjetter added hygiene Improve code quality and reduce maintenance overhead asyncio labels Nov 16, 2022
@fjetter fjetter changed the title [Draft] Confusing Nanny on_exit callback structure Confusing Nanny on_exit callback structure Nov 16, 2022
@fjetter fjetter linked a pull request Apr 10, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
asyncio hygiene Improve code quality and reduce maintenance overhead
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant