From 9ec8fdd53849998a31001d319dedb1cec47d4005 Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Fri, 26 Dec 2025 15:08:56 -0800 Subject: [PATCH] fix: close routed storage connections per iteration in show command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The defer-in-loop pattern was causing all routed storage connections to accumulate until function exit. This could lead to resource leaks when showing multiple routed issues. Now explicitly close each connection after processing each issue. (bd-uu8p) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- cmd/bd/show.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/cmd/bd/show.go b/cmd/bd/show.go index a9b50ff8..300d2e4a 100644 --- a/cmd/bd/show.go +++ b/cmd/bd/show.go @@ -88,14 +88,17 @@ var showCmd = &cobra.Command{ // First, handle routed IDs via direct mode for _, id := range routedArgs { result, err := resolveAndGetIssueWithRouting(ctx, store, id) - if result != nil { - defer result.Close() - } if err != nil { + if result != nil { + result.Close() + } fmt.Fprintf(os.Stderr, "Error fetching %s: %v\n", id, err) continue } if result == nil || result.Issue == nil { + if result != nil { + result.Close() + } fmt.Fprintf(os.Stderr, "Issue %s not found\n", id) continue } @@ -130,6 +133,7 @@ var showCmd = &cobra.Command{ fmt.Println() displayIdx++ } + result.Close() // Close immediately after processing each routed ID } // Then, handle local IDs via daemon @@ -314,19 +318,23 @@ var showCmd = &cobra.Command{ for idx, id := range args { // Resolve and get issue with routing (e.g., gt-xyz routes to gastown) result, err := resolveAndGetIssueWithRouting(ctx, store, id) - if result != nil { - defer result.Close() - } if err != nil { + if result != nil { + result.Close() + } fmt.Fprintf(os.Stderr, "Error fetching %s: %v\n", id, err) continue } if result == nil || result.Issue == nil { + if result != nil { + result.Close() + } fmt.Fprintf(os.Stderr, "Issue %s not found\n", id) continue } issue := result.Issue issueStore := result.Store // Use the store that contains this issue + // Note: result.Close() called at end of loop iteration if jsonOutput { // Include labels, dependencies (with metadata), dependents (with metadata), and comments in JSON output @@ -358,6 +366,7 @@ var showCmd = &cobra.Command{ details.Comments, _ = issueStore.GetIssueComments(ctx, issue.ID) allDetails = append(allDetails, details) + result.Close() // Close before continuing to next iteration continue } @@ -518,6 +527,7 @@ var showCmd = &cobra.Command{ } fmt.Println() + result.Close() // Close routed storage after each iteration } if jsonOutput && len(allDetails) > 0 {