Skip to content

Commit

Permalink
event: fix data race
Browse files Browse the repository at this point in the history
This is definitely the best fix, but I'm committing this one to make the
build green again. The event monitoring code can definitely take some
love, I'll try to refactor it over the weekend.
  • Loading branch information
fsouza committed Apr 25, 2016
1 parent c8917ab commit 681783e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,19 @@ func (eventState *eventMonitoringState) monitorEvents(c *Client) {

func (eventState *eventMonitoringState) connectWithRetry(c *Client) error {
var retries int
err := c.eventHijack(atomic.LoadInt64(&eventState.lastSeen), eventState.C, eventState.errC)
eventState.RLock()
eventChan := eventState.C
errChan := eventState.errC
eventState.RUnlock()
err := c.eventHijack(atomic.LoadInt64(&eventState.lastSeen), eventChan, errChan)
for ; err != nil && retries < maxMonitorConnRetries; retries++ {
waitTime := int64(retryInitialWaitTime * math.Pow(2, float64(retries)))
time.Sleep(time.Duration(waitTime) * time.Millisecond)
err = c.eventHijack(atomic.LoadInt64(&eventState.lastSeen), eventState.C, eventState.errC)
eventState.RLock()
eventChan = eventState.C
errChan = eventState.errC
eventState.RUnlock()
err = c.eventHijack(atomic.LoadInt64(&eventState.lastSeen), eventChan, errChan)
}
return err
}
Expand Down

0 comments on commit 681783e

Please sign in to comment.