Skip to content

Commit

Permalink
Close dag fetcher iterables once finished
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Feb 2, 2022
1 parent a584105 commit d6a3780
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions db/fetcher/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ func (hf *HeadFetcher) Start(ctx context.Context, txn core.Txn, spans core.Spans
}

var err error
if hf.kvIter != nil {
// If an existing iterator is to be replaced, we must still may sure it is properly closed
err = hf.kvIter.Close()
if err != nil {
return err
}
}
hf.kvIter, err = txn.Headstore().Query(ctx, q)
if err != nil {
return err
Expand Down Expand Up @@ -133,6 +140,10 @@ func (hf *HeadFetcher) FetchNext() (*cid.Cid, error) {
return hf.cid, nil
}

func (hf *HeadFetcher) Close() error {
return hf.kvIter.Close()
}

/*
// List returns the list of current heads plus the max height.
// @todo Document Heads.List function
Expand Down
4 changes: 3 additions & 1 deletion query/graphql/planner/dagscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ func (h *headsetScanNode) Values() map[string]interface{} {
}
}

func (h *headsetScanNode) Close() error { return nil }
func (h *headsetScanNode) Close() error {
return h.fetcher.Close()
}

func (h *headsetScanNode) Source() planNode { return nil }

Expand Down

0 comments on commit d6a3780

Please sign in to comment.