fix concurrent SetError in add command
I believe this also fixes a potential go routine leak (on race). License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
Steven Allen committed
Nov 20, 2017 at 19:44 UTC
d89a4b6960b48c973a59e12b0591e11bb21a4932
1 file changed
+8
-4
core/commands/add.go
+8
-4
@@ -342,6 +342,8 @@ You can now check what blocks have been created by:
342
},
343
PostRun: map[cmds.EncodingType]func(cmds.Request, cmds.ResponseEmitter) cmds.ResponseEmitter{
344
cmds.CLI: func(req cmds.Request, re cmds.ResponseEmitter) cmds.ResponseEmitter {
345
+ ctx := req.Context()
346
+
347
reNext, res := cmds.NewChanResponsePair(req)
348
outChan := make(chan interface{})
349
@@ -429,9 +431,6 @@ You can now check what blocks have been created by:
431
bar.ShowBar = true
432
bar.ShowTimeLeft = true
433
}
432
- case <-req.Context().Done():
433
- re.SetError(req.Context().Err(), cmdkit.ErrNormal)
434
- return
434
}
435
}
436
}
@@ -469,7 +468,12 @@ You can now check what blocks have been created by:
468
return
469
}
470
472
- outChan <- v
471
+ select {
472
+ case outChan <- v:
473
+ case <-ctx.Done():
474
+ re.SetError(ctx.Err(), cmdkit.ErrNormal)
475
+ return
476
+ }
477
}
478
}()
479