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:
@@ -114,8 +114,8 @@ type Storage = storage.Storage
|
||||
|
||||
// NewSQLiteStorage opens a bd SQLite database for programmatic access.
|
||||
// Most extensions should use this to query ready work and update issue status.
|
||||
func NewSQLiteStorage(dbPath string) (Storage, error) {
|
||||
return sqlite.New(dbPath)
|
||||
func NewSQLiteStorage(ctx context.Context, dbPath string) (Storage, error) {
|
||||
return sqlite.New(ctx, dbPath)
|
||||
}
|
||||
|
||||
// FindDatabasePath discovers the bd database path using bd's standard search order:
|
||||
@@ -364,9 +364,9 @@ func FindAllDatabases() []DatabaseInfo {
|
||||
dbPath := matches[0]
|
||||
// Don't fail if we can't open/query the database - it might be locked
|
||||
// or corrupted, but we still want to detect and warn about it
|
||||
store, err := sqlite.New(dbPath)
|
||||
ctx := context.Background()
|
||||
store, err := sqlite.New(ctx, dbPath)
|
||||
if err == nil {
|
||||
ctx := context.Background()
|
||||
if issues, err := store.SearchIssues(ctx, "", types.IssueFilter{}); err == nil {
|
||||
issueCount = len(issues)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user