Data race on close
Open
Nobody has claimed this yet.
Stale
- Dominant language
- Go
- Stars
- 15.8k
- Forks
- 1.3k
- Avg merge
- 2m
- Merged PRs (30d)
- 1
Description
Describe the bug
We encountered a data race in our automated tests. It is potentially difficult to replicate but here is the stack trace.
WARNING: DATA RACE
Read at 0x00c000b64d30 by goroutine 2204:
runtime.chansend()
/opt/hostedtoolcache/go/1.25.5/x64/src/runtime/chan.go:176 +0x0
github.com/dgraph-io/badger/v4.(*DB).sendToWriteCh()
/home/runner/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/db.go:904 +0x3c4
github.com/dgraph-io/badger/v4.(*Txn).commitAndSend()
/home/runner/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/txn.go:593 +0x15d8
github.com/dgraph-io/badger/v4.(*Txn).Commit()
/home/runner/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/txn.go:663 +0x218
Previous write at 0x00c000b64d30 by goroutine 1311:
runtime.closechan()
/opt/hostedtoolcache/go/1.25.5/x64/src/runtime/chan.go:414 +0x0
github.com/dgraph-io/badger/v4.(*DB).close()
/home/runner/go/pkg/mod/github.com/dgraph-io/badger/v4@v4.8.0/db.go:550 +0x31c
github.com/dgraph-io/badger/v4.(*DB).Close.func1()
/home/runner/_work/defradb/defradb/internal/db/store.go:149 +0x2c5
To Reproduce
Steps to reproduce the behavior:
Test badger with -race.
Expected behavior
No data race present.
Screenshots
N/A
Environment
Runner info available here: https://github.com/sourcenetwork/defradb/actions/runs/20442873100/job/58739759303?pr=4212
Additional context
N/A
Contributor guide
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.
Research direction
The race involves DB.close in db.go and transaction commit paths in txn.go, with the caller stack also naming internal/db/store.go. Start by testing Badger with -race and tracing the close/send paths; done means the reported data race no longer appears.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 42/100