From f4d10a92abc46bf0156ff1b475304471c16405da Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 13 Apr 2023 02:42:56 -0600 Subject: Try to find misuses of textui.Progress - Add a runtime-check to Progress to notice if we deadlocked or forgot to call .Done(). - Add a runtime-check to Progress.Done() to panic if .Set() was never called (instead of the old behavior of deadlocking). - grep: Use `defer` when possible, to help remember to call .Done(). - grep: Always either call .Set() right away, or right before calling .Done(). --- cmd/btrfs-rec/inspect/rebuildtrees/scan.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cmd/btrfs-rec/inspect/rebuildtrees/scan.go') diff --git a/cmd/btrfs-rec/inspect/rebuildtrees/scan.go b/cmd/btrfs-rec/inspect/rebuildtrees/scan.go index f266dab..b1469ff 100644 --- a/cmd/btrfs-rec/inspect/rebuildtrees/scan.go +++ b/cmd/btrfs-rec/inspect/rebuildtrees/scan.go @@ -73,6 +73,7 @@ func ScanDevices(_ctx context.Context, fs *btrfs.FS, nodeList []btrfsvol.Logical progressWriter.Set(stats) for _, laddr := range nodeList { if err := ctx.Err(); err != nil { + progressWriter.Done() return ScanDevicesResult{}, err } node, err := fs.AcquireNode(ctx, laddr, btrfstree.NodeExpectations{ @@ -80,6 +81,7 @@ func ScanDevices(_ctx context.Context, fs *btrfs.FS, nodeList []btrfsvol.Logical }) if err != nil { fs.ReleaseNode(node) + progressWriter.Done() return ScanDevicesResult{}, err } ret.insertNode(node) -- cgit v1.2.3-2-g168b