DocumentIterator usage can corrupt data if you forget to zero/nil your buffer
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from a8m/documentdb
-
Does not compileOpenhelp wanted
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
a8m/documentdb#22 · 1 comment ·
-
help wanted
Difficulty 4/5 3-5 days Newbie friendliness 30/100
a8m/documentdb#31 · 2 comments · 3 reactions ·
-
Query sub arrayOpen
Difficulty 4/5 3-5 days Newbie friendliness 30/100
a8m/documentdb#12 · 1 comment ·
-
v0.2.0 tasksOpen
Difficulty 3/5 1-2 days Newbie friendliness 45/100
a8m/documentdb#3 ·
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
prime-radiant-inc/evener#3726 ·
Maintainers usually reply within 1 day
-
[BUG] Async engine endpoint-label relationship counts include pending relationships of every typeOpen
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
modelcontextprotocol/go-sdk#1340 ·
Maintainers usually reply within 1 day
-
🪲 bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
binwiederhier/ntfy#1992 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
MHSanaei/3x-ui#6731 · 1 comment ·
Maintainers usually reply within 1 day