Skip to content
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

Prevent operations on exited HCS objects. #1567

Merged
merged 1 commit into from
Dec 7, 2022

Conversation

helsaawy
Copy link
Contributor

@helsaawy helsaawy commented Nov 18, 2022

Add checks to hcs.System to prevent attempting to shutdown or terminate a compute system that has already been stopped.
The same checks could be added to other operations (eg, pause, start, resume) but it is unclear what error should be returned in those situations, so those operations are left untouched.

Add checks to hcs.Process to prevent attempting to kill a stopped process.
Although hcs.Process differs from hcs.System in that the latter returns an error if the system is already stopped or closed, but the former does not.
Therefore, (*Process).Kill returns ErrProcessAlreadyStopped, which is the expected error in (*hcsExec).Kill.

Finally, an additional check is added to (*Process).CloseStdin to skip sending a modify request to the process to close stdin if the process has already been stopped.
(And (*Process).CloseStdin now creates a span, similar to (*Process).CloseStd(out|err)).

The motivation for this came from (*UtilityVM).Close() calling Terminate on the compute system, even if (*UtilityVM).Terminate() was already called.

Signed-off-by: Hamza El-Saawy hamzaelsaawy@microsoft.com

@helsaawy helsaawy requested a review from a team as a code owner November 18, 2022 01:44
@helsaawy helsaawy marked this pull request as draft November 18, 2022 15:41
Add checks to `hcs.System` to prevent attempting to shutdown or
terminate a compute system that has already been stopped.
The same checks could be added to other operations (eg, pause, start,
resume) but it is unclear what error should be returned in those
situations, so those operations are left untouched.

Add checks to `hcs.Process` to prevent attempting to kill a
stopped process.
Although `hcs.Process` differs from `hcs.System` in that the latter
returns an error if the system is already stopped or closed, but the
former does not.
Therefore, `(*Process).Kill` returns `ErrProcessAlreadyStopped`, which
is the expected error in `(*hcsExec).Kill`.

Finally, an additional check is added to `(*Process).CloseStdin` to skip
sending a modify request to the process to close stdin if the process
has already been stopped.
(And creating a span, similar to `(*Process).CloseStd(out|err)`).

The motivation for this came from `(*UtilityVM).Close()` calling
`Terminate` on the compute system, even if the uVM was already killed
prior.

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
@helsaawy helsaawy marked this pull request as ready for review November 18, 2022 18:32
@helsaawy helsaawy merged commit 3e090b0 into microsoft:main Dec 7, 2022
@helsaawy helsaawy deleted the double-close branch December 7, 2022 02:04
princepereira pushed a commit to princepereira/hcsshim that referenced this pull request Aug 29, 2024
Add checks to `hcs.System` to prevent attempting to shutdown or
terminate a compute system that has already been stopped.
The same checks could be added to other operations (eg, pause, start,
resume) but it is unclear what error should be returned in those
situations, so those operations are left untouched.

Add checks to `hcs.Process` to prevent attempting to kill a
stopped process.
Although `hcs.Process` differs from `hcs.System` in that the latter
returns an error if the system is already stopped or closed, but the
former does not.
Therefore, `(*Process).Kill` returns `ErrProcessAlreadyStopped`, which
is the expected error in `(*hcsExec).Kill`.

Finally, an additional check is added to `(*Process).CloseStdin` to skip
sending a modify request to the process to close stdin if the process
has already been stopped.
(And creating a span, similar to `(*Process).CloseStd(out|err)`).

The motivation for this came from `(*UtilityVM).Close()` calling
`Terminate` on the compute system, even if the uVM was already killed
prior.

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants