Skip to content

Commit

Permalink
fixes to stream close panic and concurrent write to map issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nullfunc committed Jun 19, 2024
1 parent f46d500 commit 9511b3d
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/pkg/cli/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,37 @@ func Subscribe(ctx context.Context, client client.Client, services []string) (<-
}

msg := serverStream.Msg()
if msg == nil {
continue
}

servInfo := msg.GetService()
if servInfo == nil || servInfo.Service == nil {
continue
}

serviceName, ok := normalizedServiceNameToServiceName[servInfo.Service.Name]
if !ok {
term.Debugf("Unknown service %s in subscribe response\n", servInfo.Service.Name)
continue
}
serviceStatus[serviceName] = servInfo.Status
statusChan <- &serviceStatus

//make a copy to be put into channel
serviceStatusCopy := cloneServiceStatus(serviceStatus)

statusChan <- &serviceStatusCopy
term.Debugf("service %s with status %s\n", serviceName, servInfo.Status)
}
}()

return statusChan, nil
}

func cloneServiceStatus(serviceStatus map[string]string) map[string]string {
serviceStatusCopy := make(map[string]string, len(serviceStatus))
for k, v := range serviceStatus {
serviceStatusCopy[k] = v
}
return serviceStatusCopy
}

0 comments on commit 9511b3d

Please sign in to comment.