Skip to content

Data race on close #2249

@nasdf

Description

@nasdf

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/[email protected]/db.go:904 +0x3c4
  github.com/dgraph-io/badger/v4.(*Txn).commitAndSend()
      /home/runner/go/pkg/mod/github.com/dgraph-io/badger/[email protected]/txn.go:593 +0x15d8
  github.com/dgraph-io/badger/v4.(*Txn).Commit()
      /home/runner/go/pkg/mod/github.com/dgraph-io/badger/[email protected]/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/[email protected]/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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions