Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

DocumentIterator usage can corrupt data if you forget to zero/nil your buffer

Open Beginner friendly
#39 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Domain
databases

Research direction

Look at the DocumentIterator implementation in the documentdb package, likely in a file like iterator.go. Examine how the slice reference is reused across iterations. The fix involves ensuring the buffer is cleared or a new slice is allocated each iteration. Test by running the example code with and without the fix to verify data corruption is prevented.

Written by the indexing model from the issue text.

Description

Since it is a slice reference, any nested structs or arrays in your data will be sparsely overwritten during iteration and can still include old data from past iteration if you follow the docs:

	// ...
	var docs []Document

	iterator := documentdb.NewIterator(
		client, documentdb.NewDocumentIterator("coll_self_link", nil, &docs, documentdb.PartitionKey("1"), documentdb.Limit(1)),
	)

	for iterator.Next() {
		if err := iterator.Error(); err != nil {
			log.Fatal(err)
		}
		fmt.Println(len(docs))
	}    

	// ...
}```

Instead, nil the buffer like this:

func main() {
// ...
var docs []Document

iterator := documentdb.NewIterator(
	client, documentdb.NewDocumentIterator("coll_self_link", nil, &docs, documentdb.PartitionKey("1"), documentdb.Limit(1)),
)

for iterator.Next() {
	if err := iterator.Error(); err != nil {
		log.Fatal(err)
	}
	fmt.Println(len(docs))
            docs = nil // zero your buffer to avoid corrupt data!
}    

// ...

}```

Dominant language
Go
Stars
31
Forks
26
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from a8m/documentdb

All issues in a8m/documentdb

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.