Prevent calling stop or restart services during db upgrade#49098
Prevent calling stop or restart services during db upgrade#49098balloob merged 16 commits intohome-assistant:devfrom
Conversation
…grade While shutdown will block until the database upgrade is completed, the webserver will shutdown successfully which will leave the user without feedback. Instead we raise an exception when they call the service to prevent confusion.
|
Hey there @home-assistant/core, mind taking a look at this pull request as its been labeled with an integration ( |
| self._completed_database_setup = None | ||
| self._event_listener = None | ||
|
|
||
| self.async_migration_event = asyncio.Event() |
There was a problem hiding this comment.
Hmm.. there is a race here since they can call stop before startup is finished. We probably need to set this as soon as we hit the point of checking the future.
There was a problem hiding this comment.
A user would have to request a restart between when the hass_started.result call finishes and the variable is swapped. If we set the var before we check the result then they can't stop the instance because something is blocking startup which probably won't work anyways. Probably best to set it before since they upgraded intentionally and we are already at the point of no return.
There was a problem hiding this comment.
Is this event only used in tests?
|
sqlite3 commands to get the database upgrade to take a while for testing |
Hmm..I got a log message but not toast |
|
Hmm calling the service raises an exception on the backend but we get a success message back down the websocket |
|
Well that is because we explicitly do not block on these so there is no way to give feedback That's likely because we don't want to have an outstanding task that blocks shutdown. Maybe a new service for the frontend |
|
I'm going to sleep on this one |
|
Need to do more archaeology to find out why these are made blocking false forcefully |
|
These can still be tracked tasks. Since this calls async_create_task we can remove the block that was added in #15803 as it shouldn't be needed anymore, and then the UI will get feedback |
|
Shutdown can block for a while because we don't cancel setup retries at stop |
|
I'll start a new PR to cancel the ConfigEntryRetry/PlatformNotReady retry at the stop event. |
MartinHjelmare
left a comment
There was a problem hiding this comment.
Just a question above.
Breaking change
Prevent the
homeassistant.stopandhomeassistant.restartservices from doinga shutdown while a background database upgrade is in progress.
While shutdown will block until the database upgrade is completed, the webserver
will shutdown successfully which will leave the user without feedback. Instead we
abort and log an error when they call the service to prevent confusion.
These service calls previously forced
blockingtoFalsein #15803 Since we now useasyncio.create_taskthis is no longer needed and we can now give feedback to the UI / api calls when something fails.Type of change
Example entry for
configuration.yaml:# Example configuration.yamlAdditional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: