Skip to content

Commit

Permalink
(FFM-1857) Implement lock when setting up streams
Browse files Browse the repository at this point in the history
  • Loading branch information
conormurray95 committed Dec 13, 2021
1 parent ed0101c commit 5f8101c
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,22 @@ import (
// that any pending analytics events have been delivered.
//
type CfClient struct {
mux sync.RWMutex
api rest.ClientWithResponsesInterface
metricsapi metricsclient.ClientWithResponsesInterface
sdkKey string
auth rest.AuthenticationRequest
config *config
environmentID string
token string
persistence cache.Persistence
cancelFunc context.CancelFunc
streamConnected bool
authenticated chan struct{}
initialized chan bool
analyticsService *analyticsservice.AnalyticsService
clusterIdentifier string
mux sync.RWMutex
api rest.ClientWithResponsesInterface
metricsapi metricsclient.ClientWithResponsesInterface
sdkKey string
auth rest.AuthenticationRequest
config *config
environmentID string
token string
persistence cache.Persistence
cancelFunc context.CancelFunc
streamConnected bool
streamConnectedLock sync.RWMutex
authenticated chan struct{}
initialized chan bool
analyticsService *analyticsservice.AnalyticsService
clusterIdentifier string
}

// NewCfClient creates a new client instance that connects to CF with the default configuration.
Expand Down Expand Up @@ -160,7 +161,10 @@ func (c *CfClient) retrieveInitialData(ctx context.Context) {
}

func (c *CfClient) streamConnect() {
if !c.config.enableStream {
// we only ever want one stream to be setup - other threads must wait before trying to establish a connection
c.streamConnectedLock.Lock()
defer c.streamConnectedLock.Unlock()
if !c.config.enableStream || c.streamConnected {
return
}

Expand Down

0 comments on commit 5f8101c

Please sign in to comment.