-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Cleanup doesn't run when exception occurs in startup. #4799
Comments
Please use cleanup_ctx instead |
@asvetlov As I mentioned in that PR, and in the description of this issue, I am using a cleanup context. If an exception occurs in another part of the startup, the cleanup context does not get cleaned up, despite having been successfully initiated. |
Thanks for the clarification. |
This is a minimal example of what I mean. Expected behaviour is that "CLEANUP" is printed after the exception occurs.
The reason this is such a problem in my use case, is that the cleanup_ctx is actually launching a process which listens on a specific port. The cleanup part will shut down that process. If the cleanup is not run, then devtools restarts the server and spawns a new process which then fails because the old process is still bound to the port, meaning that the application breaks and I have to shutdown everything and restart devtools, which is a massive pain when trying to develop another part of the application with its own startup steps. |
This would also need a small change to devtools in order to ensure the cleanup is run, which I've suggested here: https://github.com/aio-libs/aiohttp-devtools/pull/266/files But, it won't do anything unless aiohttp ensures that the cleanup call actually does something at this stage. |
When an exception occurs in startup, the cleanup is never run.
Expected behaviour: Any cleanup steps added should be run, especially when using the cleanup-context.
e.g.
Task A = Setup DB as cleanup context.
Task B = Setup a remote connection as cleanup context. This throws an exception.
Actual behaviour:
Task A is successfully setup.
Task B creates an exception.
No cleanup happens.
Expected behaviour:
Task A is successfully setup.
Task B creates an exception.
Task A cleanup happens.
The text was updated successfully, but these errors were encountered: