Skip to content

Commit d89a4b6

Browse files
committed
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 <[email protected]>
1 parent 65489c1 commit d89a4b6

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

core/commands/add.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ You can now check what blocks have been created by:
342342
},
343343
PostRun: map[cmds.EncodingType]func(cmds.Request, cmds.ResponseEmitter) cmds.ResponseEmitter{
344344
cmds.CLI: func(req cmds.Request, re cmds.ResponseEmitter) cmds.ResponseEmitter {
345+
ctx := req.Context()
346+
345347
reNext, res := cmds.NewChanResponsePair(req)
346348
outChan := make(chan interface{})
347349

@@ -429,9 +431,6 @@ You can now check what blocks have been created by:
429431
bar.ShowBar = true
430432
bar.ShowTimeLeft = true
431433
}
432-
case <-req.Context().Done():
433-
re.SetError(req.Context().Err(), cmdkit.ErrNormal)
434-
return
435434
}
436435
}
437436
}
@@ -469,7 +468,12 @@ You can now check what blocks have been created by:
469468
return
470469
}
471470

472-
outChan <- v
471+
select {
472+
case outChan <- v:
473+
case <-ctx.Done():
474+
re.SetError(ctx.Err(), cmdkit.ErrNormal)
475+
return
476+
}
473477
}
474478
}()
475479

0 commit comments

Comments
 (0)