Ensure the proxy service shuts down properly in case of partial init #50710
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.
While fixing a flaky test in #50702 I observed that both
process.Close()
andprocess.Shutdown()
were hanging.Down the rabbit hole was the
initProxyEndpoint
doing an incomplete startup and not cleaning up the services it started.This PR ensures that
proxy.shutdown
is registered before we start running theproxy.*
components so we have a chance to cleanup even if something goes wrong and we never finish the init.Explanation:
In the PR I linked, I tried to wait for shutdown before cleaning up channels created by the test. This failed because
initProxyEndpoint
:proxy.web
service withoutprocess.ExitContext()
(http.Server
doesn't take any context)db:proxy
authClient
to retrieve information and can fail to get createdproxy.web
server and causing theproxy.web
service to exit.Now if anything else bad happens between the
proxy:web
registration and theproxy.shutdown
registration (e.g. we do a shutdown and close the auth client), theproxy.web
service will continue to run and block the shutdown. This also leaves dangling routines and resources. This is an issue in tests as we quickly start/stop teleport instances.