Skip to content

Commit c8cc629

Browse files
committed
Fix context issue
Signed-off-by: bpopovschi <[email protected]>
1 parent 5422bb1 commit c8cc629

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

runtime/service.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,7 @@ func (s *service) StopVM(requestCtx context.Context, request *proto.StopVMReques
506506
} else {
507507
timeout = time.Duration(request.VMShutdownTimeoutSeconds) * time.Second
508508
}
509-
ctx, cancel := context.WithTimeout(requestCtx, timeout)
510-
defer cancel()
509+
timer := time.NewTimer(timeout)
511510
defer logPanicAndDie(s.logger)
512511
// If something goes wrong here, just shut down ungracefully. This eliminates some scenarios that would result
513512
// in the user being unable to shut down the VM.
@@ -526,12 +525,12 @@ func (s *service) StopVM(requestCtx context.Context, request *proto.StopVMReques
526525
shutdownCh := make(chan error)
527526
go func() {
528527
defer close(shutdownCh)
529-
_, err = s.Shutdown(ctx, &taskAPI.ShutdownRequest{Now: true})
528+
_, err = s.Shutdown(requestCtx, &taskAPI.ShutdownRequest{Now: true})
530529
shutdownCh <- err
531530
}()
532531

533532
select {
534-
case <-ctx.Done():
533+
case <-timer.C:
535534
return nil, status.Error(codes.DeadlineExceeded, "timed out waiting for VM shutdown")
536535
case err = <-shutdownCh:
537536
if err != nil {

runtime/service_integ_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ func TestMultipleVMs_Isolated(t *testing.T) {
441441

442442
containerWg.Wait()
443443

444-
_, err = fcClient.StopVM(ctx, &proto.StopVMRequest{VMID: strconv.Itoa(vmID), VMShutdownTimeoutSeconds: 10})
444+
_, err = fcClient.StopVM(ctx, &proto.StopVMRequest{VMID: strconv.Itoa(vmID), VMShutdownTimeoutSeconds: 5})
445445
require.NoError(t, err, "failed to stop VM %d", vmID)
446446
}(vmID)
447447
}

0 commit comments

Comments
 (0)