Skip to content

Commit

Permalink
fix concurrent SetError in add command
Browse files Browse the repository at this point in the history
I believe this also fixes a potential go routine leak (on race).

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
  • Loading branch information
Stebalien committed Nov 21, 2017
1 parent 5012c6a commit d4e8838
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ You can now check what blocks have been created by:
},
PostRun: map[cmds.EncodingType]func(cmds.Request, cmds.ResponseEmitter) cmds.ResponseEmitter{
cmds.CLI: func(req cmds.Request, re cmds.ResponseEmitter) cmds.ResponseEmitter {
ctx := req.Context()

reNext, res := cmds.NewChanResponsePair(req)
outChan := make(chan interface{})

Expand Down Expand Up @@ -429,9 +431,6 @@ You can now check what blocks have been created by:
bar.ShowBar = true
bar.ShowTimeLeft = true
}
case <-req.Context().Done():
re.SetError(req.Context().Err(), cmdkit.ErrNormal)
return
}
}
}
Expand Down Expand Up @@ -469,7 +468,12 @@ You can now check what blocks have been created by:
return
}

outChan <- v
select {
case outChan <- v:
case <-ctx.Done():
re.SetError(ctx.Err(), cmdkit.ErrNormal)
return
}
}
}()

Expand Down

0 comments on commit d4e8838

Please sign in to comment.