From 26a3b4aa85b4890de77c1424bf3681a3e33ec858 Mon Sep 17 00:00:00 2001 From: Wondertan Date: Thu, 27 Jun 2024 20:18:20 +0200 Subject: [PATCH] fix(shwap/bitswap): close acccessor in Blockstore --- share/shwap/p2p/bitswap/block_fetch_test.go | 8 ++++---- share/shwap/p2p/bitswap/block_store.go | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/share/shwap/p2p/bitswap/block_fetch_test.go b/share/shwap/p2p/bitswap/block_fetch_test.go index 59e9384e65..9b724db1ee 100644 --- a/share/shwap/p2p/bitswap/block_fetch_test.go +++ b/share/shwap/p2p/bitswap/block_fetch_test.go @@ -117,7 +117,7 @@ func TestFetch_Duplicates(t *testing.T) { func newExchangeOverEDS(ctx context.Context, t *testing.T, rsmt2d *rsmt2d.ExtendedDataSquare) exchange.SessionExchange { bstore := &Blockstore{ Getter: testAccessorGetter{ - Accessor: &eds.Rsmt2D{ExtendedDataSquare: rsmt2d}, + AccessorStreamer: &eds.Rsmt2D{ExtendedDataSquare: rsmt2d}, }, } return newExchange(ctx, t, bstore) @@ -163,11 +163,11 @@ func newClient(ctx context.Context, host host.Host, store blockstore.Blockstore) } type testAccessorGetter struct { - eds.Accessor + eds.AccessorStreamer } -func (t testAccessorGetter) GetByHeight(context.Context, uint64) (eds.Accessor, error) { - return t.Accessor, nil +func (t testAccessorGetter) GetByHeight(context.Context, uint64) (eds.AccessorStreamer, error) { + return t.AccessorStreamer, nil } type testFetcher struct { diff --git a/share/shwap/p2p/bitswap/block_store.go b/share/shwap/p2p/bitswap/block_store.go index d42b40704e..38b6fc368a 100644 --- a/share/shwap/p2p/bitswap/block_store.go +++ b/share/shwap/p2p/bitswap/block_store.go @@ -14,7 +14,7 @@ import ( // network height. type AccessorGetter interface { // GetByHeight returns an Accessor by its height. - GetByHeight(ctx context.Context, height uint64) (eds.Accessor, error) + GetByHeight(ctx context.Context, height uint64) (eds.AccessorStreamer, error) } // Blockstore implements generalized Bitswap compatible storage over Shwap containers @@ -38,6 +38,11 @@ func (b *Blockstore) getBlock(ctx context.Context, cid cid.Cid) (blocks.Block, e if err != nil { return nil, fmt.Errorf("getting EDS Accessor for height %v: %w", blk.Height(), err) } + defer func() { + if err := eds.Close(); err != nil { + log.Warnf("failed to close EDS accessor for height %v: %s", blk.Height(), err) + } + }() if err = blk.Populate(ctx, eds); err != nil { return nil, fmt.Errorf("failed to populate Shwap Block on height %v for %s: %w", blk.Height(), spec.String(), err)