controller: finish remote controller when all session finished #2010
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.
#1641
This PR tries to implement automatic cleanup of the remote controller suggested by @jedevc on #1641 .
Most of the items listed in that issue seem already implemented through the previous works. So this PR mainly focuses on implementing automatic exiting of the remote server when there is no session (caa83a6), which hasn't been implemented. This is implemented by periodically (every 10s) checking the number of sessions managed on the server. If there is no session, sever automatically exits.
Please note that this PR doesn't implement automatic finishing of a session after a deadline (mainly because I'm not sure how long the deadline should be).
example
Session can be finished using
disconnect
.On another terminal, we can see the server automatically exits after 10s of the disconnection.
Implementation details for #1641
The following shows details about each item listed in #1641 :
1. when they exit
: Container(processes) exits when all processes exit (managed by BuildKit).2. when their parent session terminates
: When a session closes, it kills all processes using*processes.Manager.CancelRunningProcesses()
. (local, remote)1. when it is explicitly terminated by the user
: Implemented bydisconnect
command on the monitor. (this PR a fix for local controller: eb2b88b)2. when its parent controller is terminated (for local, when the calling process ends, for remote, when the server terminates)
:remote.Server.Close()
.3. after a deadline during which no user interaction has occurred
: not implemented. I'm not sure about how long the timeout should be.1. the user requests it to using kill
: Implemented bykill
command on the monitor.2. it has no more sessions
: Implemented by this PR (caa83a6).