dgraph-io/badger · error
errNoRoom
errNoRoom
Error message
No room for write
What it means
errNoRoom ("No room for write") is returned by ensureRoomForWrite, which blocks until the memtable can be flushed to make room for an incoming write. It is returned to the caller when the DB is closed while a writer waits on flushCond, or when a write cannot proceed because there is no room.
Source
Thrown at db.go:1040
// error occurs, it will be passed back via the callback.
//
// err := kv.BatchSetAsync(entries, func(err error)) {
// Check(err)
// }
func (db *DB) batchSetAsync(entries []*Entry, f func(error)) error {
req, err := db.sendToWriteCh(entries)
if err != nil {
return err
}
go func() {
err := req.Wait()
// Write is complete. Let's call the callback function now.
f(err)
}()
return nil
}
var errNoRoom = errors.New("No room for write")
// ensureRoomForWrite is always called serially. It blocks (without busy-polling)
// until the current memtable can be flushed, i.e. until flushChan has room.
func (db *DB) ensureRoomForWrite() error {
var err error
db.lock.Lock()
defer db.lock.Unlock()
y.AssertTrue(db.mt != nil) // A nil mt indicates that DB is being closed.
if !db.mt.isFull() {
return nil
}
for {
select {
case db.flushChan <- db.mt:
db.opt.Debugf("Flushing memtable, mt.size=%d size of flushChan: %d\n",
db.mt.sl.MemSize(), len(db.flushChan))View on GitHub (pinned to 2a001d466f)
Solutions
- Ensure all writers finish before calling db.Close() (use a WaitGroup)
- Retry writes that return errNoRoom after checking db.IsClosed()
- Check disk space/health if it appears while the DB is still open
Example fix
// before
go func(){ txn.Commit() }()
db.Close() // writer may get errNoRoom
// after
wg.Wait() // wait for all writers
db.Close() Defensive patterns
Strategy: retry
Validate before calling
if db.IsClosed() { return errors.New("db closed; not writing") } Try / catch
for {
err := db.Write(ctx, entries)
if err == nil { break }
if errors.Is(err, badger.ErrNoRoom) || err.Error() == "No room for write" {
if db.IsClosed() { return err }
time.Sleep(50 * time.Millisecond); continue
}
return err
} Prevention
- Join all writers (WaitGroup) before db.Close()
- Don't submit writes from goroutines outliving the DB
- Monitor disk space; a stalled flusher worsens backpressure
When it happens
Trigger: Calling db.Write/Commit concurrently with db.Close(); writeCallbacks loop sees IsClosed() while waiting; writes continuing after close started, or memtable flush backpressure with a closed/stalled flusher.
Common situations: App shutdown racing in-flight writes; not waiting for pending transactions before Close; flush pipeline stalled (disk full) combined with close.
Related errors
AI-assisted analysis of dgraph-io/badger@2a001d466f (2026-09-05).
Data as JSON: /api/errors/f1e1d6fff4ef1522.
Report an issue: GitHub.