From ca7eaed4dd9c0a49fb7b85d5c77ba5265b92bc56 Mon Sep 17 00:00:00 2001 From: Dmitry Nikolaev Date: Tue, 26 Nov 2024 11:10:13 +0100 Subject: [PATCH] Fix uninitialized channel Signed-off-by: Dmitry Nikolaev --- grafana/rmf-app/pkg/plugin/dds/client.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/grafana/rmf-app/pkg/plugin/dds/client.go b/grafana/rmf-app/pkg/plugin/dds/client.go index 8dd3561..74bf52d 100644 --- a/grafana/rmf-app/pkg/plugin/dds/client.go +++ b/grafana/rmf-app/pkg/plugin/dds/client.go @@ -55,6 +55,7 @@ type Client struct { headerMap *HeaderMap stopChan chan struct{} + closeOnce sync.Once waitGroup sync.WaitGroup rwMutex sync.RWMutex } @@ -72,6 +73,7 @@ func NewClient(baseUrl string, username string, password string, timeout int, tl }, }, }, + stopChan: make(chan struct{}), } client.waitGroup.Add(1) go client.sync() @@ -99,9 +101,11 @@ func (c *Client) sync() { } func (c *Client) Close() { - close(c.stopChan) - c.waitGroup.Wait() - c.httpClient.CloseIdleConnections() + c.closeOnce.Do(func() { + close(c.stopChan) + c.waitGroup.Wait() + c.httpClient.CloseIdleConnections() + }) } func (c *Client) Get(ctx context.Context, path string, params ...string) (*Response, error) {