mirror of https://github.com/linkerd/linkerd2.git
cli: handle panic caused by `linkerd metrics` port-forward failure (#4007)
* cli: handle `linkerd metrics` port-forward gracefully - add return for routine in func `Init()` in case of error - add return from func `getMetrics()` if error from `portforward.Init()` * Remove select block at pkg/k8s/portforward.go - It is now the caller's responsibility to call pf.Stop() Signed-off-by: Mayank Shah <mayankshah1614@gmail.com>
This commit is contained in:
parent
df2011dbb2
commit
7cff974a79
|
@ -165,6 +165,7 @@ func getMetrics(
|
|||
defer portforward.Stop()
|
||||
if err = portforward.Init(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error running port-forward: %s", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
metricsURL := portforward.URLFor("/metrics")
|
||||
|
|
|
@ -177,14 +177,7 @@ func (pf *PortForward) Init() error {
|
|||
go func() {
|
||||
if err := pf.run(); err != nil {
|
||||
failure <- err
|
||||
}
|
||||
|
||||
select {
|
||||
case <-pf.GetStop():
|
||||
// stopCh was closed, do nothing
|
||||
default:
|
||||
// pf.run() returned for some other reason, close stopCh
|
||||
pf.Stop()
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -203,6 +196,7 @@ func (pf *PortForward) Init() error {
|
|||
}
|
||||
|
||||
// Stop terminates the port-forward connection.
|
||||
// It is the caller's responsibility to call Stop even in case of errors
|
||||
func (pf *PortForward) Stop() {
|
||||
close(pf.stopCh)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue