Skip to content

Commit

Permalink
fix panic from race in task master (influxdata#798)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathaniel Cook authored Aug 8, 2016
1 parent 16c2e1b commit 7b8ac77
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ The corresponding alert states are:
- [#783](https://github.com/influxdata/kapacitor/pull/783): Fix panic when revoking tokens not already defined.
- [#784](https://github.com/influxdata/kapacitor/pull/784): Fix several issues with comment formatting in TICKscript.
- [#786](https://github.com/influxdata/kapacitor/issues/786): Deleting tags now updates the group by dimensions if needed.

- [#772](https://github.com/influxdata/kapacitor/issues/772): Delete task snapshot data when a task is deleted.
- [#797](https://github.com/influxdata/kapacitor/issues/797): Fix panic from race condition in task master.

## v1.0.0-beta4 [2016-07-27]

Expand Down
24 changes: 20 additions & 4 deletions task_master.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,12 @@ func (tm *TaskMaster) runForking(in *Edge) {

func (tm *TaskMaster) forkPoint(p models.Point) {
tm.mu.RLock()
defer tm.mu.RUnlock()
locked := true
defer func() {
if locked {
tm.mu.RUnlock()
}
}()

// Create the fork keys - which is (db, rp, measurement)
key := forkKey{
Expand Down Expand Up @@ -511,9 +516,20 @@ func (tm *TaskMaster) forkPoint(p models.Point) {

c, ok := tm.forkStats[key]
if !ok {
// Create statistics
c = &expvar.Int{}
tm.forkStats[key] = c
// Release read lock
tm.mu.RUnlock()
locked = false

// Get write lock
tm.mu.Lock()
// Now with write lock check again
c, ok = tm.forkStats[key]
if !ok {
// Create statistics
c = &expvar.Int{}
tm.forkStats[key] = c
}
tm.mu.Unlock()

tags := map[string]string{
"task_master": tm.id,
Expand Down

0 comments on commit 7b8ac77

Please sign in to comment.