Skip to content

Fix silent wget failures in DownloadFile causing corrupted .bak file downloads #588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 23, 2025

When downloading .bak files from HTTP servers during container creation, users experienced mysterious "corrupted file" errors despite files appearing to download successfully. The issue was caused by silent wget failures that weren't being detected or reported.

Problem

Users running commands like:

sqlcmd create mssql --name express --accept-eula --using http://localhost:3000/files/WideWorldImporters-Full.bak

Would see:

  • Files appeared to download (correct size shown in container)
  • But database restore failed with "The volume on device '/var/opt/mssql/backup/WideWorldImporters-Full.bak' is empty"
  • No error messages during the download process

Root Cause

The DownloadFile function in internal/container/controller.go was:

  1. Ignoring wget errors: The function called runCmdInContainer() but ignored the returned stdout/stderr
  2. Using incompatible wget flags: GNU wget flags didn't work with BusyBox wget in Alpine containers
  3. Not validating downloads: No verification that files actually existed after download

When containers tried to access localhost URLs (which fails due to container networking), wget would fail silently.

Solution

1. Added Comprehensive Error Detection

// Before: Silent failures
c.runCmdInContainer(id, cmd)

// After: Proper error checking
stdout, stderr = c.runCmdInContainer(id, cmd)
if len(stderr) > 0 {
    stderrStr := string(stderr)
    if strings.Contains(stderrStr, "Connection refused") ||
       strings.Contains(stderrStr, "404 Not Found") ||
       // ... other error conditions {
        panic("wget download failed: " + stderrStr)
    }
}

2. Fixed BusyBox Compatibility

// Before: GNU wget flags (unsupported)
cmd = []string{"wget", "--no-check-certificate", "--timeout=300", "--tries=3", "--progress=dot:mega", "-O", file, src}

// After: BusyBox-compatible flags
cmd = []string{"wget", "-T", "300", "-t", "3", "-O", file, src}

3. Added File Validation

  • Verify downloaded files actually exist
  • Provide clear error messages when downloads fail

User Impact

Before Fix

Downloading WideWorldImporters-Full.bak
Restoring database WideWorldImporters-Full
ERROR: The volume on device '/var/opt/mssql/backup/WideWorldImporters-Full.bak' is empty.

After Fix

Downloading WideWorldImporters-Full.bak
panic: wget download failed: Connecting to 127.0.0.1:3000 (127.0.0.1:3000)
wget: can't connect to remote host (127.0.0.1): Connection refused

Users now get clear, actionable error messages and can use proper solutions:

  • External URLs: https://example.com/files/database.bak
  • Host networking: http://host.docker.internal:3000/files/database.bak
  • Proper container networking configuration

Testing

  • Added comprehensive error detection tests
  • Verified existing functionality remains intact
  • Added documentation about container networking limitations

Fixes #566.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits June 23, 2025 20:46
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
…roperly

Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Bak restore from local http server corrupted file Fix silent wget failures in DownloadFile causing corrupted .bak file downloads Jun 23, 2025
@Copilot Copilot AI requested a review from shueybubbles June 23, 2025 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bak restore from local http server corrupted file
2 participants