mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-24 02:31:12 +00:00
Merge pull request #6774 from bpradipt/fix-6730
CC | runtime: Add configurable context timeout for StopVM
This commit is contained in:
commit
3b9ae6716c
@ -134,6 +134,15 @@ func (rh *remoteHypervisor) AttestVM(ctx context.Context) error {
|
||||
|
||||
func (rh *remoteHypervisor) StopVM(ctx context.Context, waitOnly bool) error {
|
||||
|
||||
// waitOnly doesn't make sense for remote hypervisor and suited for local hypervisor.
|
||||
// Instead use a similar logic like StartVM to handle StopVM with timeout.
|
||||
|
||||
timeout := defaultMinTimeout
|
||||
|
||||
if rh.config.RemoteHypervisorTimeout > 0 {
|
||||
timeout = int(rh.config.RemoteHypervisorTimeout)
|
||||
}
|
||||
|
||||
s, err := openRemoteService(rh.config.RemoteHypervisorSocket)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -143,8 +152,11 @@ func (rh *remoteHypervisor) StopVM(ctx context.Context, waitOnly bool) error {
|
||||
req := &pb.StopVMRequest{
|
||||
Id: string(rh.sandboxID),
|
||||
}
|
||||
ctx2, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
|
||||
defer cancel()
|
||||
|
||||
if _, err := s.client.StopVM(context.Background(), req); err != nil {
|
||||
logrus.Printf("calling remote hypervisor StopVM (timeout: %d)", timeout)
|
||||
if _, err := s.client.StopVM(ctx2, req); err != nil {
|
||||
return fmt.Errorf("remote hypervisor call failed: %w", err)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user