sudo-project / sudo

Utility to execute a command as another user
https://www.sudo.ws
Other
1.15k stars 208 forks source link

Asynchronous execution of sudo in parallel breaks terminal #312

Closed sylv-io closed 9 months ago

sylv-io commented 9 months ago

Regarding the issue addressed here: https://github.com/go-task/task/issues/1369, it looks like there is a regression that causes the tty to break when sudo is running in parallel. As mentioned in the above issue, it does not require a password prompt to break and can be reproduced by this simple go application:

 package main

import (
        "log"
        "os"
        "os/exec"
        "sync"
)

const NumExecutions = 3

func main() {
        var wg sync.WaitGroup

        for i := 0; i < NumExecutions; i++ {
                wg.Add(1)

                go func() {
                        defer wg.Done()

                        cmd := exec.Command("sudo", "true")

                        cmd.Stdin = os.Stdin
                        cmd.Stdout = os.Stdout
                        cmd.Stderr = os.Stderr

                        err := cmd.Run()
                        if err != nil {
                                log.Fatal(err)
                        }
                }()
        }

        wg.Wait()
}

I'm pretty sure this didn't happen about 1 year ago, so I'm currently trying to bisect this bug.

sylv-io commented 9 months ago

I can confirm that this bug does not occur with sudo v1.9.0.

millert commented 9 months ago

Can you check whether setting

Defaults !use_pty

in the sudoers file works around the problem?

sylv-io commented 9 months ago

Can you check whether setting

Defaults !use_pty

in the sudoers file works around the problem?

hi @millert You are correct. This is indeed a workaround for the problem. :+1:

sylv-io commented 9 months ago

I git bisected and as expected, this is the breaking commit: Enable the use_pty option by default for sudo 1.9.14. 894daa88f66a69d3c6fe4d2255183d4c0b33a464

millert commented 9 months ago

Fixed by fabb626

sylv-io commented 9 months ago

Thanks :+1: