hyperledger / fabric

Hyperledger Fabric is an enterprise-grade permissioned distributed ledger framework for developing solutions and applications. Its modular and versatile design satisfies a broad range of industry use cases. It offers a unique approach to consensus that enables performance at scale while preserving privacy.
https://wiki.hyperledger.org/display/fabric
Apache License 2.0
15.76k stars 8.86k forks source link

Block stream should be closed after used. #4992

Open datbeohbbh opened 1 month ago

datbeohbbh commented 1 month ago

Current Status

https://github.com/hyperledger/fabric/blob/94590aa4332b20350e8aee5572a8cfd29164221c/common/ledger/blkstorage/blockfile_mgr.go#L425-L428

A block stream is opened to sync block index. After used, we should close that block stream.

Expected

The block stream stream is closed after used.

Solution

simply add defer stream.close().

var stream *blockStream
if stream, err = newBlockStream(mgr.rootDir, startFileNum, int64(startOffset), endFileNum); err != nil {
    return err
}
defer stream.close() // close stream

Please let us know if you plan to work on this.

Maybe.