@@ -19,7 +19,7 @@ import (
19
19
"github.com/sirupsen/logrus"
20
20
)
21
21
22
- func StopGracefully (inst * store.Instance , isRestart bool ) error {
22
+ func StopGracefully (ctx context. Context , inst * store.Instance , isRestart bool ) error {
23
23
if inst .Status != store .StatusRunning {
24
24
if isRestart {
25
25
logrus .Warn ("The instance is not running, continuing with the restart" )
@@ -35,17 +35,17 @@ func StopGracefully(inst *store.Instance, isRestart bool) error {
35
35
}
36
36
37
37
logrus .Info ("Waiting for the host agent and the driver processes to shut down" )
38
- err := waitForHostAgentTermination (context . TODO () , inst , begin )
38
+ err := waitForHostAgentTermination (ctx , inst , begin )
39
39
if err != nil {
40
40
return err
41
41
}
42
42
43
43
logrus .Info ("Waiting for the instance to shut down" )
44
- return waitForInstanceShutdown (context . TODO () , inst )
44
+ return waitForInstanceShutdown (ctx , inst )
45
45
}
46
46
47
47
func waitForHostAgentTermination (ctx context.Context , inst * store.Instance , begin time.Time ) error {
48
- ctx2 , cancel := context .WithTimeout (ctx , 3 * time .Minute + 10 * time .Second )
48
+ ctx , cancel := context .WithTimeout (ctx , 3 * time .Minute + 10 * time .Second )
49
49
defer cancel ()
50
50
51
51
var receivedExitingEvent bool
@@ -63,7 +63,7 @@ func waitForHostAgentTermination(ctx context.Context, inst *store.Instance, begi
63
63
haStdoutPath := filepath .Join (inst .Dir , filenames .HostAgentStdoutLog )
64
64
haStderrPath := filepath .Join (inst .Dir , filenames .HostAgentStderrLog )
65
65
66
- if err := hostagentevents .Watch (ctx2 , haStdoutPath , haStderrPath , begin , onEvent ); err != nil {
66
+ if err := hostagentevents .Watch (ctx , haStdoutPath , haStderrPath , begin , onEvent ); err != nil {
67
67
return err
68
68
}
69
69
@@ -75,7 +75,7 @@ func waitForHostAgentTermination(ctx context.Context, inst *store.Instance, begi
75
75
}
76
76
77
77
func waitForInstanceShutdown (ctx context.Context , inst * store.Instance ) error {
78
- ctx2 , cancel := context .WithTimeout (ctx , 3 * time .Minute )
78
+ ctx , cancel := context .WithTimeout (ctx , 3 * time .Minute )
79
79
defer cancel ()
80
80
81
81
ticker := time .NewTicker (500 * time .Millisecond )
@@ -93,7 +93,7 @@ func waitForInstanceShutdown(ctx context.Context, inst *store.Instance) error {
93
93
logrus .Infof ("The instance %s has shut down" , updatedInst .Name )
94
94
return nil
95
95
}
96
- case <- ctx2 .Done ():
96
+ case <- ctx .Done ():
97
97
return errors .New ("timed out waiting for instance to shut down after 3 minutes" )
98
98
}
99
99
}
0 commit comments