Commit f1b50941 authored by Kostas Christidis's avatar Kostas Christidis
Browse files

[FAB-8584] Prevent deliver panic on closed iterator



The file-based ledger implementation of the iterator does not account
for the case where another thread may close the iterator, resulting in
the return of a (nil, nil) pair (block and error respectively).

This changeset addresses that.

Change-Id: Id77b311b60a8a3c64c4350fcaf9d3b5bf993bf87
Signed-off-by: default avatarKostas Christidis <kostas@christidis.io>
parent f4e31309
......@@ -26,7 +26,7 @@ import (
"github.com/op/go-logging"
)
const pkgLogID = "orderer/ledger/fileledger"
const pkgLogID = "common/ledger/blockledger/file"
var logger *logging.Logger
......@@ -63,11 +63,16 @@ type fileLedgerIterator struct {
commonIterator ledger.ResultsIterator
}
// Next blocks until there is a new block available, or returns an error if the
// next block is no longer retrievable
// Next blocks until there is a new block available, or until Close is called.
// It returns an error if the next block is no longer retrievable.
func (i *fileLedgerIterator) Next() (*cb.Block, cb.Status) {
result, err := i.commonIterator.Next()
if err != nil {
logger.Error(err)
return nil, cb.Status_SERVICE_UNAVAILABLE
}
// Cover the case where another thread calls Close on the iterator.
if result == nil {
return nil, cb.Status_SERVICE_UNAVAILABLE
}
return result.(*cb.Block), cb.Status_SUCCESS
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment