Skip to content

Commit f096ff7

Browse files
committed
[FAB-10154] Close RWSetScanner at end of use
There is a missing call to Close() after obtaining the RWSetScanner and iterating over the results, in the private data support for the endorser plugins. Change-Id: I645ae82f2e985188b1d526461695aaf24a77674e Signed-off-by: yacovm <yacovm@il.ibm.com>
1 parent ec1f138 commit f096ff7

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

core/endorser/plugin_endorser_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ func (fep *fakeEndorsementPlugin) Init(dependencies ...endorsement.Dependency) e
234234
}
235235

236236
type rwsetScanner struct {
237+
mock.Mock
237238
data []*rwset.TxPvtReadWriteSet
238239
}
239240

@@ -254,8 +255,8 @@ func (rws *rwsetScanner) NextWithConfig() (*transientstore.EndorserPvtSimulation
254255
}, nil
255256
}
256257

257-
func (*rwsetScanner) Close() {
258-
panic("implement me")
258+
func (rws *rwsetScanner) Close() {
259+
rws.Called()
259260
}
260261

261262
func TestTransientStore(t *testing.T) {
@@ -312,6 +313,7 @@ func TestTransientStore(t *testing.T) {
312313
scanner := &rwsetScanner{
313314
data: []*rwset.TxPvtReadWriteSet{rws},
314315
}
316+
scanner.On("Close")
315317

316318
transientStore.On("GetTxPvtRWSetByTxid", mock.Anything, mock.Anything).Return(scanner, nil)
317319

@@ -322,4 +324,5 @@ func TestTransientStore(t *testing.T) {
322324
err = proto.Unmarshal(resp.Payload, txrws)
323325
assert.NoError(t, err)
324326
assert.Equal(t, rws, txrws)
327+
scanner.AssertCalled(t, "Close")
325328
}

core/endorser/state.go

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func (sc *StateContext) GetTransientByTXID(txID string) ([]*rwset.TxPvtReadWrite
5151
if err != nil {
5252
return nil, errors.WithStack(err)
5353
}
54+
defer scanner.Close()
5455
var data []*rwset.TxPvtReadWriteSet
5556
for {
5657
res, err := scanner.NextWithConfig()

0 commit comments

Comments
 (0)