From b191c99a053c04d34faf8f1dc3c04b8693e544c8 Mon Sep 17 00:00:00 2001 From: VihasMakwana <121151420+VihasMakwana@users.noreply.github.com> Date: Wed, 25 Feb 2026 14:16:19 +0530 Subject: [PATCH] fix: panic in the main hierarchy Signed-off-by: VihasMakwana <121151420+VihasMakwana@users.noreply.github.com> --- CHANGELOG/CHANGELOG-1.5.md | 1 + db.go | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG/CHANGELOG-1.5.md b/CHANGELOG/CHANGELOG-1.5.md index efa387aa9..64a47bee6 100644 --- a/CHANGELOG/CHANGELOG-1.5.md +++ b/CHANGELOG/CHANGELOG-1.5.md @@ -6,5 +6,6 @@ - [Add support for data file size limit](https://github.com/etcd-io/bbolt/pull/929) - [Remove the unused txs list](https://github.com/etcd-io/bbolt/pull/973) - [Add option `NoStatistics` to make the statistics optional](https://github.com/etcd-io/bbolt/pull/977) +- [Move panic handling from goroutine to the parent function](https://github.com/etcd-io/bbolt/pull/1153)
\ No newline at end of file diff --git a/db.go b/db.go index 5d3e26496..96db07b35 100644 --- a/db.go +++ b/db.go @@ -1253,13 +1253,16 @@ func (db *DB) freepages() []common.Pgid { reachable := make(map[common.Pgid]*common.Page) nofreed := make(map[common.Pgid]bool) ech := make(chan error) + go func() { - for e := range ech { - panic(fmt.Sprintf("freepages: failed to get all reachable pages (%v)", e)) - } + defer close(ech) + tx.recursivelyCheckBucket(&tx.root, reachable, nofreed, HexKVStringer(), ech) }() - tx.recursivelyCheckBucket(&tx.root, reachable, nofreed, HexKVStringer(), ech) - close(ech) + // following for loop will exit once channel is closed in the above goroutine. + // we don't need to wait explictly with a waitgroup + for e := range ech { + panic(fmt.Sprintf("freepages: failed to get all reachable pages (%v)", e)) + } // TODO: If check bucket reported any corruptions (ech) we shouldn't proceed to freeing the pages.