File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -298,6 +298,12 @@ func (it *randomIterator) pickTree() *clientTree {
298298 it .mu .Lock ()
299299 defer it .mu .Unlock ()
300300
301+ // First check if iterator was closed.
302+ // Need to do this here to avoid nil map access in rebuildTrees.
303+ if it .trees == nil {
304+ return nil
305+ }
306+
301307 // Rebuild the trees map if any links have changed.
302308 if it .lc .changed {
303309 it .rebuildTrees ()
Original file line number Diff line number Diff line change @@ -115,6 +115,21 @@ func TestIterator(t *testing.T) {
115115 checkIterator (t , it , nodes )
116116}
117117
118+ func TestIteratorCloseWithoutNext (t * testing.T ) {
119+ tree1 , url1 := makeTestTree ("t1" , nil , nil )
120+ c := NewClient (Config {Resolver : newMapResolver (tree1 .ToTXT ("t1" ))})
121+ it , err := c .NewIterator (url1 )
122+ if err != nil {
123+ t .Fatal (err )
124+ }
125+
126+ it .Close ()
127+ ok := it .Next ()
128+ if ok {
129+ t .Fatal ("Next returned true after Close" )
130+ }
131+ }
132+
118133// This test checks if closing randomIterator races.
119134func TestIteratorClose (t * testing.T ) {
120135 nodes := testNodes (nodesSeed1 , 500 )
You can’t perform that action at this time.
0 commit comments