fix deadlock issue, switch to frames envelope

This commit is contained in:
Drew Bailey
2019-10-30 16:56:24 -04:00
parent 873969cf41
commit 58117c03c4
4 changed files with 18 additions and 15 deletions

View File

@@ -105,9 +105,6 @@ func (d *Monitor) Start(stopCh <-chan struct{}) <-chan []byte {
// Write attempts to send latest log to logCh
// it drops the log if channel is unavailable to receive
func (d *Monitor) Write(p []byte) (n int, err error) {
d.Lock()
defer d.Unlock()
bytes := make([]byte, len(p))
copy(bytes, p)

View File

@@ -89,7 +89,7 @@ func (c *MonitorCommand) Run(args []string) int {
Params: params,
}
eventDoneCh := make(chan struct{})
logCh, err := client.Agent().Monitor(eventDoneCh, query)
frames, err := client.Agent().Monitor(eventDoneCh, query)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error starting monitor: %s", err))
c.Ui.Error(commandErrorText(c))
@@ -101,11 +101,11 @@ func (c *MonitorCommand) Run(args []string) int {
OUTER:
for {
select {
case log, ok := <-logCh:
case frame, ok := <-frames:
if !ok {
break OUTER
}
c.Ui.Output(log)
c.Ui.Output(string(frame.Data))
}
}