@@ -206,32 +206,30 @@ type RpcClient struct {
206
206
207
207
func (r * RpcClient ) Call (serviceMethod string , args any , reply any ) error {
208
208
var err error
209
- var new * RpcClient
209
+ cl := r
210
210
for i := 0 ; i < connectFailureMaxTries ; i ++ {
211
- if r != nil {
212
- if err = r .client .Call (serviceMethod , args , reply ); err != nil {
213
- log .Warnf ("rpc call %s failed (attempt %d): %v" , serviceMethod , i , err )
214
- if i == connectFailureMaxTries - 1 {
215
- return err
216
- }
217
-
218
- time .Sleep (10 * time .Second )
219
- r .Close ()
220
- new , _ , err = Instrument (r .component , r .agentName , r .namespace , r .kubeconfig , r .kclient , r .opts ... )
221
- if err != nil {
222
- time .Sleep (10 * time .Second )
223
- continue
224
- }
225
- r = new
226
- }
227
- } else {
228
- new , _ , err = Instrument (r .component , r .agentName , r .namespace , r .kubeconfig , r .kclient , r .opts ... )
211
+ if cl == nil {
212
+ cl , _ , err = Instrument (r .component , r .agentName , r .namespace , r .kubeconfig , r .kclient , r .opts ... )
229
213
if err != nil {
214
+ log .Warnf ("failed to re-instrument (attempt %d): %v" , i , err )
230
215
time .Sleep (10 * time .Second )
231
216
continue
232
217
}
233
- r = new
234
218
}
219
+
220
+ err = cl .client .Call (serviceMethod , args , reply )
221
+ if err == nil {
222
+ return nil
223
+ }
224
+
225
+ log .Warnf ("rpc call %s failed (attempt %d): %v" , serviceMethod , i , err )
226
+ if i == connectFailureMaxTries - 1 {
227
+ return err
228
+ }
229
+
230
+ time .Sleep (10 * time .Second )
231
+ cl .Close ()
232
+ cl = nil // Try to Instrument again next attempt
235
233
}
236
234
return err
237
235
}
446
444
func shutdownAgent (podExec * PodExec , kubeconfig string , podName string , namespace string , containerName string ) error {
447
445
cmd := []string {"curl" , "localhost:8080/shutdown" }
448
446
_ , _ , _ , err := podExec .ExecCmd (cmd , podName , namespace , containerName )
449
- return err
447
+ if err != nil {
448
+ return fmt .Errorf ("curl failed: %v" , err )
449
+ }
450
+ return nil
450
451
}
451
452
452
453
func getFreePort () (int , error ) {
0 commit comments