From e9c3788b3ecf9cf38fec25814365a2e40816f44a Mon Sep 17 00:00:00 2001 From: camrynl <31013536+camrynl@users.noreply.github.com> Date: Thu, 20 Oct 2022 08:56:37 -0700 Subject: [PATCH 1/2] implement select case --- telemetry/telemetrybuffer.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/telemetry/telemetrybuffer.go b/telemetry/telemetrybuffer.go index 3db6c8c207..8149b514cb 100644 --- a/telemetry/telemetrybuffer.go +++ b/telemetry/telemetrybuffer.go @@ -216,7 +216,12 @@ func (tb *TelemetryBuffer) Write(b []byte) (c int, err error) { // Cancel - signal to tear down telemetry buffer func (tb *TelemetryBuffer) Cancel() { - tb.cancel <- true + select { + case tb.cancel <- true: + log.Logf("server cancel") + default: + log.Logf("Cancel fn: default case: no message sent") + } } // Close - close all connections From b86e94c3b1e4aa2d992671d84e67cc5f118bce28 Mon Sep 17 00:00:00 2001 From: camrynl <31013536+camrynl@users.noreply.github.com> Date: Thu, 20 Oct 2022 10:24:29 -0700 Subject: [PATCH 2/2] remove calls to tb.cancel() in telemetry.go --- telemetry/telemetry.go | 8 +------- telemetry/telemetrybuffer.go | 7 +------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/telemetry/telemetry.go b/telemetry/telemetry.go index 9a8aed3ccd..395b840a65 100644 --- a/telemetry/telemetry.go +++ b/telemetry/telemetry.go @@ -111,10 +111,8 @@ func (reportMgr *ReportManager) SendReport(tb *TelemetryBuffer) error { if tb != nil && tb.Connected { report, err = reportMgr.ReportToBytes() if err == nil { - // If write fails, try to re-establish connections as server/client if _, err = tb.Write(report); err != nil { log.Printf("telemetry write failed:%v", err) - tb.Cancel() } } } @@ -124,7 +122,6 @@ func (reportMgr *ReportManager) SendReport(tb *TelemetryBuffer) error { // ReportToBytes - returns the report bytes func (reportMgr *ReportManager) ReportToBytes() ([]byte, error) { - switch reportMgr.Report.(type) { case *CNIReport: case *AIMetric: @@ -145,9 +142,8 @@ func SendCNIMetric(cniMetric *AIMetric, tb *TelemetryBuffer) error { reportMgr := &ReportManager{Report: cniMetric} report, err = reportMgr.ReportToBytes() if err == nil { - // If write fails, try to re-establish connections as server/client if _, err = tb.Write(report); err != nil { - tb.Cancel() + log.Printf("Error writing to telemetry socket:%v", err) } } } @@ -160,10 +156,8 @@ func SendCNIEvent(tb *TelemetryBuffer, report *CNIReport) { reportMgr := &ReportManager{Report: report} reportBytes, err := reportMgr.ReportToBytes() if err == nil { - // If write fails, try to re-establish connections as server/client if _, err = tb.Write(reportBytes); err != nil { log.Printf("Error writing to telemetry socket:%v", err) - tb.Cancel() } } } diff --git a/telemetry/telemetrybuffer.go b/telemetry/telemetrybuffer.go index 8149b514cb..3db6c8c207 100644 --- a/telemetry/telemetrybuffer.go +++ b/telemetry/telemetrybuffer.go @@ -216,12 +216,7 @@ func (tb *TelemetryBuffer) Write(b []byte) (c int, err error) { // Cancel - signal to tear down telemetry buffer func (tb *TelemetryBuffer) Cancel() { - select { - case tb.cancel <- true: - log.Logf("server cancel") - default: - log.Logf("Cancel fn: default case: no message sent") - } + tb.cancel <- true } // Close - close all connections