Skip to content

Commit 43aa8f9

Browse files
committed
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 <[email protected]>
1 parent 7f2af48 commit 43aa8f9

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

internal/sqltest/native/mysql.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,18 @@ func startMySQLServer(ctx context.Context) (string, error) {
9696
if _, err := exec.LookPath("mysql"); err != nil {
9797
slog.Info("native/mysql", "status", "installing")
9898

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

110-
// Try to install MySQL server (with timeout)
111-
installCtx, installCancel := context.WithTimeout(ctx, 60*time.Second)
112-
defer installCancel()
113-
cmd := exec.CommandContext(installCtx, "sudo", "apt-get", "install", "-y", "-qq", "mysql-server")
109+
// Try to install MySQL server (with 60 second timeout using Linux timeout command)
110+
cmd := exec.Command("sudo", "timeout", "60", "apt-get", "install", "-y", "-qq", "mysql-server")
114111
cmd.Env = append(os.Environ(), "DEBIAN_FRONTEND=noninteractive")
115112
if output, err := cmd.CombinedOutput(); err != nil {
116113
// If apt-get fails (no network or timeout), return error

0 commit comments

Comments
 (0)