Skip to content

Commit 37e96de

Browse files
committed
fix strict mode
This commits fixes a timing bug where `DB.StrictMode` can panic before the goroutine reading the database can finish. If an error is found in strict mode then it now finishes reading the entire database before panicking.
1 parent 0fd4c05 commit 37e96de

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

tx.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io"
66
"os"
77
"sort"
8+
"strings"
89
"time"
910
"unsafe"
1011
)
@@ -202,8 +203,17 @@ func (tx *Tx) Commit() error {
202203
// If strict mode is enabled then perform a consistency check.
203204
// Only the first consistency error is reported in the panic.
204205
if tx.db.StrictMode {
205-
if err, ok := <-tx.Check(); ok {
206-
panic("check fail: " + err.Error())
206+
ch := tx.Check()
207+
var errs []string
208+
for {
209+
err, ok := <-ch
210+
if !ok {
211+
break
212+
}
213+
errs = append(errs, err.Error())
214+
}
215+
if len(errs) > 0 {
216+
panic("check fail: " + strings.Join(errs, "\n"))
207217
}
208218
}
209219

0 commit comments

Comments
 (0)