Skip to content
Prev Previous commit
Next Next commit
fix: add timeout to MySQL apt-get installation
Add context timeout to prevent apt-get install from blocking indefinitely
when network is unavailable or slow. Uses 60 second timeout for install
and 10 second timeout for debconf setup.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
  • Loading branch information
claude committed Dec 18, 2025
commit 7f2af48e387bbf6645f57abb117fa7ce8cee6bf6
16 changes: 10 additions & 6 deletions internal/sqltest/native/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,25 @@ func startMySQLServer(ctx context.Context) (string, error) {
if _, err := exec.LookPath("mysql"); err != nil {
slog.Info("native/mysql", "status", "installing")

// Pre-configure MySQL root password
setSelectionsCmd := exec.Command("sudo", "bash", "-c",
// Pre-configure MySQL root password (with timeout)
debconfCtx, debconfCancel := context.WithTimeout(ctx, 10*time.Second)
defer debconfCancel()
setSelectionsCmd := exec.CommandContext(debconfCtx, "sudo", "bash", "-c",
`echo "mysql-server mysql-server/root_password password mysecretpassword" | sudo debconf-set-selections && `+
`echo "mysql-server mysql-server/root_password_again password mysecretpassword" | sudo debconf-set-selections`)
setSelectionsCmd.Env = append(os.Environ(), "DEBIAN_FRONTEND=noninteractive")
if output, err := setSelectionsCmd.CombinedOutput(); err != nil {
slog.Debug("native/mysql", "debconf", string(output))
}

// Try to install MySQL server
cmd := exec.Command("sudo", "apt-get", "install", "-y", "-qq", "mysql-server")
// Try to install MySQL server (with timeout)
installCtx, installCancel := context.WithTimeout(ctx, 60*time.Second)
defer installCancel()
cmd := exec.CommandContext(installCtx, "sudo", "apt-get", "install", "-y", "-qq", "mysql-server")
cmd.Env = append(os.Environ(), "DEBIAN_FRONTEND=noninteractive")
if output, err := cmd.CombinedOutput(); err != nil {
// If apt-get fails (no network), return error
return "", fmt.Errorf("apt-get install mysql-server failed (network may be unavailable): %w\n%s", err, output)
// If apt-get fails (no network or timeout), return error
return "", fmt.Errorf("apt-get install mysql-server failed (network may be unavailable or timed out): %w\n%s", err, output)
}
}

Expand Down
Loading