Skip to content

Commit b191c99

Browse files
committed
fix: panic in the main hierarchy
Signed-off-by: VihasMakwana <121151420+VihasMakwana@users.noreply.github.com>
1 parent 641bf5b commit b191c99

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

CHANGELOG/CHANGELOG-1.5.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
- [Add support for data file size limit](https://github.com/etcd-io/bbolt/pull/929)
77
- [Remove the unused txs list](https://github.com/etcd-io/bbolt/pull/973)
88
- [Add option `NoStatistics` to make the statistics optional](https://github.com/etcd-io/bbolt/pull/977)
9+
- [Move panic handling from goroutine to the parent function](https://github.com/etcd-io/bbolt/pull/1153)
910

1011
<hr>

db.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,13 +1253,16 @@ func (db *DB) freepages() []common.Pgid {
12531253
reachable := make(map[common.Pgid]*common.Page)
12541254
nofreed := make(map[common.Pgid]bool)
12551255
ech := make(chan error)
1256+
12561257
go func() {
1257-
for e := range ech {
1258-
panic(fmt.Sprintf("freepages: failed to get all reachable pages (%v)", e))
1259-
}
1258+
defer close(ech)
1259+
tx.recursivelyCheckBucket(&tx.root, reachable, nofreed, HexKVStringer(), ech)
12601260
}()
1261-
tx.recursivelyCheckBucket(&tx.root, reachable, nofreed, HexKVStringer(), ech)
1262-
close(ech)
1261+
// following for loop will exit once channel is closed in the above goroutine.
1262+
// we don't need to wait explictly with a waitgroup
1263+
for e := range ech {
1264+
panic(fmt.Sprintf("freepages: failed to get all reachable pages (%v)", e))
1265+
}
12631266

12641267
// TODO: If check bucket reported any corruptions (ech) we shouldn't proceed to freeing the pages.
12651268

0 commit comments

Comments
 (0)