From 9200024e50b1bca0eb9da4704473fc856e3ab122 Mon Sep 17 00:00:00 2001 From: Alexander Renz Date: Fri, 16 Jan 2026 19:36:52 +0100 Subject: [PATCH] fix(restore): add context validity checks to debug cancellation issues Added explicit context checks at critical points: 1. After extraction completes - logs error if context was cancelled 2. Before database restore loop starts - catches premature cancellation This helps diagnose issues where all database restores fail with 'context cancelled' even though extraction completed successfully. The user reported this happening after 4h20m extraction - all 6 DBs showed 'restore skipped (context cancelled)'. These checks will log exactly when/where the context becomes invalid. --- bin/README.md | 4 ++-- internal/restore/engine.go | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/bin/README.md b/bin/README.md index 1869d8d..744ffd1 100644 --- a/bin/README.md +++ b/bin/README.md @@ -4,8 +4,8 @@ This directory contains pre-compiled binaries for the DB Backup Tool across mult ## Build Information - **Version**: 3.42.50 -- **Build Time**: 2026-01-16_15:09:21_UTC -- **Git Commit**: dd7c4da +- **Build Time**: 2026-01-16_17:31:38_UTC +- **Git Commit**: 698b8a7 ## Recent Updates (v1.1.0) - ✅ Fixed TUI progress display with line-by-line output diff --git a/internal/restore/engine.go b/internal/restore/engine.go index e956010..45442d2 100755 --- a/internal/restore/engine.go +++ b/internal/restore/engine.go @@ -910,6 +910,16 @@ func (e *Engine) RestoreCluster(ctx context.Context, archivePath string) error { return fmt.Errorf("failed to extract archive: %w", err) } + // Check context validity after extraction (debugging context cancellation issues) + if ctx.Err() != nil { + e.log.Error("Context cancelled after extraction - this should not happen", + "context_error", ctx.Err(), + "extraction_completed", true) + operation.Fail("Context cancelled unexpectedly") + return fmt.Errorf("context cancelled after extraction completed: %w", ctx.Err()) + } + e.log.Info("Extraction completed, context still valid") + // Check if user has superuser privileges (required for ownership restoration) e.progress.Update("Checking privileges...") isSuperuser, err := e.checkSuperuser(ctx) @@ -1108,6 +1118,18 @@ func (e *Engine) RestoreCluster(ctx context.Context, archivePath string) error { var successCount, failCount int32 var mu sync.Mutex // Protect shared resources (progress, logger) + // CRITICAL: Check context before starting database restore loop + // This helps debug issues where context gets cancelled between extraction and restore + if ctx.Err() != nil { + e.log.Error("Context cancelled before database restore loop started", + "context_error", ctx.Err(), + "total_databases", totalDBs, + "parallelism", parallelism) + operation.Fail("Context cancelled before database restores could start") + return fmt.Errorf("context cancelled before database restore: %w", ctx.Err()) + } + e.log.Info("Starting database restore loop", "databases", totalDBs, "parallelism", parallelism) + // Timing tracking for restore phase progress restorePhaseStart := time.Now() var completedDBTimes []time.Duration // Track duration for each completed DB restore