daemon: Cleanup after a failed start #32673
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If the daemon start failed due to e.g. invalid configuration the cleanup was not performed as it was only done from the stop function that was not invoked since the daemon start had failed.
This in some situations lead to confusing crashes as hive did stop all the dependencies of the legacy daemon, for example this crash was reported:
The crash was caused by the LocalNodeStore stopping and clearing the global variable in the node package (to make sure for example our tests don't leak data across them and to make sure we do cleanup correctly), while the DNSProxy was still running in the background processing DNS packets and using the globals in the node package.
To fix this, run the cleanup functions also when "newDaemon" or "startDaemon" fails with an error.
Fixes: f21f303 ("daemon: bubble up error from startDaemon instead of fataling")