go-task/task

Asynchronous execution of sudo in parallel breaks terminal

sylv-io opened this issue · 2 comments

After running an old taskfile I wrote about a year ago, I realized that there is now a bug when multiple sudo commands are run in parallel.

You can reproduce this behavior by running this Taskfile:

version: '3'

tasks:
  default:
    deps:
      - sudo
      - sudo

  sudo:
      cmds:
      - sudo true

It is important to note that the input password prompt is not necessary to brake the terminal. It works even if the password is already cached or sudo is set to nopasswd.

i could observe multiple ways it brakes the terminal, such as not rendering the terminal input, as in this asciinema recording:
asciicast

Since this behavior was not observable 1 year ago, I assumed it must be a regression in task. However, I can also reproduce this bug with older Task versions like v2.7, indicating that it could be a regression in sudo instead.

This issue was created mainly to track the progress of the investigation of this bug, and because I'm probably not the only one using sudo to do privilege stuff in task.

  • Task version: main (f0d2551)
  • Operating system: Archlinux
  • Experiments enabled: no

This simple go application confirms that this is indeed a bug in sudo:

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 going to point this issue to sudo-project and see if this regression can be pinpointed with git bisect.

Let's keep this issue open until it's properly addressed/fixed. 👍

Bug in sudo fixed by commit fabb626.