@@ -120,29 +120,27 @@ func (c *command) initCheckCmd() error {
120120 }
121121 chk = beekeeper .NewActionMiddleware (tracer , chk , checkName )
122122
123- if checkConfig .Timeout != nil {
124- ctx , cancel = context .WithTimeout (ctx , * checkConfig .Timeout )
125- defer cancel ()
126- }
123+ checkCtx , cancelCheck := createChildContext (ctx , checkConfig .Timeout )
124+ defer cancelCheck ()
127125
128126 c .log .Infof ("running check: %s" , checkName )
129127
130128 ch := make (chan error , 1 )
131129 go func () {
132- ch <- chk .Run (ctx , cluster , o )
130+ ch <- chk .Run (checkCtx , cluster , o )
133131 close (ch )
134132 }()
135133
136134 select {
137- case <- ctx .Done ():
138- deadline , ok := ctx .Deadline ()
135+ case <- checkCtx .Done ():
136+ deadline , ok := checkCtx .Deadline ()
139137 if ok {
140- return fmt .Errorf ("running check %s: %w: deadline %v" , checkName , ctx .Err (), deadline )
138+ return fmt .Errorf ("running check %s: %w: deadline %v" , checkName , checkCtx .Err (), deadline )
141139 }
142- return fmt .Errorf ("running check %s: %w" , checkName , ctx .Err ())
140+ return fmt .Errorf ("check %s failed due to : %w" , checkName , checkCtx .Err ())
143141 case err = <- ch :
144142 if err != nil {
145- return fmt .Errorf ("running check %s: %w" , checkName , err )
143+ return fmt .Errorf ("check %s failed with error : %w" , checkName , err )
146144 }
147145 c .log .Infof ("%s check completed successfully" , checkName )
148146 }
@@ -164,3 +162,10 @@ func (c *command) initCheckCmd() error {
164162
165163 return nil
166164}
165+
166+ func createChildContext (ctx context.Context , timeout * time.Duration ) (context.Context , context.CancelFunc ) {
167+ if timeout != nil {
168+ return context .WithTimeout (ctx , * timeout )
169+ }
170+ return context .WithCancel (ctx )
171+ }
0 commit comments