Skip to content
Prev Previous commit
Next Next commit
fix: use Linux timeout command for apt-get installation
Use the Linux timeout command instead of context timeout for apt-get
since exec.CommandContext doesn't properly kill child processes when
using sudo. This ensures apt-get is properly terminated after 60 seconds.

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

Co-Authored-By: Claude <noreply@anthropic.com>
  • Loading branch information
claude committed Dec 18, 2025
commit 43aa8f96dc63bfb7c4f9ec5120784729cee117ce
13 changes: 5 additions & 8 deletions internal/sqltest/native/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,18 @@ 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 (with timeout)
debconfCtx, debconfCancel := context.WithTimeout(ctx, 10*time.Second)
defer debconfCancel()
setSelectionsCmd := exec.CommandContext(debconfCtx, "sudo", "bash", "-c",
// Pre-configure MySQL root password (with timeout using Linux timeout command)
setSelectionsCmd := exec.Command("sudo", "timeout", "10",
"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 (with timeout)
installCtx, installCancel := context.WithTimeout(ctx, 60*time.Second)
defer installCancel()
cmd := exec.CommandContext(installCtx, "sudo", "apt-get", "install", "-y", "-qq", "mysql-server")
// Try to install MySQL server (with 60 second timeout using Linux timeout command)
cmd := exec.Command("sudo", "timeout", "60", "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 or timeout), return error
Expand Down
Loading