Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2)
Complete implementation of signal-aware context propagation for graceful cancellation across all commands and storage operations. Key changes: 1. Signal-aware contexts (bd-rtp): - Added rootCtx/rootCancel in main.go using signal.NotifyContext() - Set up in PersistentPreRun, cancelled in PersistentPostRun - Daemon uses same pattern in runDaemonLoop() - Handles SIGINT/SIGTERM for graceful shutdown 2. Context propagation (bd-yb8): - All commands now use rootCtx instead of context.Background() - sqlite.New() receives context for cancellable operations - Database operations respect context cancellation - Storage layer propagates context through all queries 3. Cancellation tests (bd-2o2): - Added import_cancellation_test.go with comprehensive tests - Added export cancellation test in export_test.go - Tests verify database integrity after cancellation - All cancellation tests passing Fixes applied during review: - Fixed rootCtx lifecycle (removed premature defer from PersistentPreRun) - Fixed test context contamination (reset rootCtx in test cleanup) - Fixed export tests missing context setup Impact: - Pressing Ctrl+C during import/export now cancels gracefully - No database corruption or hanging transactions - Clean shutdown of all operations Tested: - go build ./cmd/bd ✓ - go test ./cmd/bd -run TestImportCancellation ✓ - go test ./cmd/bd -run TestExportCommand ✓ - Manual Ctrl+C testing verified 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -20,7 +20,7 @@ var labelCmd = &cobra.Command{
|
||||
// Helper function to process label operations for multiple issues
|
||||
func processBatchLabelOperation(issueIDs []string, label string, operation string, jsonOut bool,
|
||||
daemonFunc func(string, string) error, storeFunc func(context.Context, string, string, string) error) {
|
||||
ctx := context.Background()
|
||||
ctx := rootCtx
|
||||
results := []map[string]interface{}{}
|
||||
for _, issueID := range issueIDs {
|
||||
var err error
|
||||
@@ -71,7 +71,7 @@ var labelAddCmd = &cobra.Command{
|
||||
// Use global jsonOutput set by PersistentPreRun
|
||||
issueIDs, label := parseLabelArgs(args)
|
||||
// Resolve partial IDs
|
||||
ctx := context.Background()
|
||||
ctx := rootCtx
|
||||
resolvedIDs := make([]string, 0, len(issueIDs))
|
||||
for _, id := range issueIDs {
|
||||
var fullID string
|
||||
@@ -116,7 +116,7 @@ var labelRemoveCmd = &cobra.Command{
|
||||
// Use global jsonOutput set by PersistentPreRun
|
||||
issueIDs, label := parseLabelArgs(args)
|
||||
// Resolve partial IDs
|
||||
ctx := context.Background()
|
||||
ctx := rootCtx
|
||||
resolvedIDs := make([]string, 0, len(issueIDs))
|
||||
for _, id := range issueIDs {
|
||||
var fullID string
|
||||
@@ -158,7 +158,7 @@ var labelListCmd = &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// Use global jsonOutput set by PersistentPreRun
|
||||
ctx := context.Background()
|
||||
ctx := rootCtx
|
||||
// Resolve partial ID first
|
||||
var issueID string
|
||||
if daemonClient != nil {
|
||||
@@ -228,7 +228,7 @@ var labelListAllCmd = &cobra.Command{
|
||||
Short: "List all unique labels in the database",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// Use global jsonOutput set by PersistentPreRun
|
||||
ctx := context.Background()
|
||||
ctx := rootCtx
|
||||
var issues []*types.Issue
|
||||
var err error
|
||||
// Use daemon if available
|
||||
|
||||
Reference in New Issue
Block a user