Skip to content

Commit

Permalink
[FAB-8584] Prevent deliver panic on closed iterator
Browse files Browse the repository at this point in the history
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: Kostas Christidis <kostas@christidis.io>
  • Loading branch information
kchristidis committed Mar 1, 2018
1 parent f4e3130 commit f1b5094
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions common/ledger/blockledger/file/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f1b5094

Please sign in to comment.