diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2016-03-21 08:49:39 -0600 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2016-03-21 08:59:39 -0600 |
commit | 37e96de68dcc7f3ee75e2a96410b2688553d9b82 (patch) | |
tree | 89b96bd54ea84732fbfc3e8298986aeb0b0d3089 | |
parent | Merge pull request #528 from boltdb/windows (diff) | |
download | dedo-37e96de68dcc7f3ee75e2a96410b2688553d9b82.tar.gz dedo-37e96de68dcc7f3ee75e2a96410b2688553d9b82.tar.xz |
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.
-rw-r--r-- | tx.go | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -5,6 +5,7 @@ import ( "io" "os" "sort" + "strings" "time" "unsafe" ) @@ -202,8 +203,17 @@ func (tx *Tx) Commit() error { // If strict mode is enabled then perform a consistency check. // Only the first consistency error is reported in the panic. if tx.db.StrictMode { - if err, ok := <-tx.Check(); ok { - panic("check fail: " + err.Error()) + ch := tx.Check() + var errs []string + for { + err, ok := <-ch + if !ok { + break + } + errs = append(errs, err.Error()) + } + if len(errs) > 0 { + panic("check fail: " + strings.Join(errs, "\n")) } } |