Skip to content

Commit 708c493

Browse files
committedApr 13, 2018
[FAB-9124] Fix race in nextBlock
Send result over chan instead of using shared, named return value. Change-Id: I3c5edbdbd792f7787a21f6de7f2fde2df5ffd9b5 Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent 265a43f commit 708c493

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed
 

‎common/deliver/deliver.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -306,16 +306,21 @@ func (h *Handler) validateChannelHeader(ctx context.Context, chdr *cb.ChannelHea
306306
return nil
307307
}
308308

309-
func nextBlock(cursor blockledger.Iterator, cancel <-chan struct{}) (block *cb.Block, status cb.Status) {
310-
done := make(chan struct{})
309+
func nextBlock(cursor blockledger.Iterator, cancel <-chan struct{}) (*cb.Block, cb.Status) {
310+
type result struct {
311+
block *cb.Block
312+
status cb.Status
313+
}
314+
315+
resultCh := make(chan *result, 1)
311316
go func() {
312-
defer close(done)
313-
block, status = cursor.Next()
317+
block, status := cursor.Next()
318+
resultCh <- &result{block, status}
314319
}()
315320

316321
select {
317-
case <-done:
318-
return
322+
case r := <-resultCh:
323+
return r.block, r.status
319324
case <-cancel:
320325
logger.Warningf("Aborting deliver for request because of background error")
321326
return nil, cb.Status_SERVICE_UNAVAILABLE

0 commit comments

Comments
 (0)
Please sign in to comment.