Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asynchronous execution of sudo in parallel breaks terminal #312

Closed
sylv-io opened this issue Oct 8, 2023 · 6 comments
Closed

Asynchronous execution of sudo in parallel breaks terminal #312

sylv-io opened this issue Oct 8, 2023 · 6 comments

Comments

@sylv-io
Copy link

sylv-io commented Oct 8, 2023

Regarding the issue addressed here: go-task/task#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 sylv-io changed the title Asynchronous execution of sudo in parallel brake terminal Asynchronous execution of sudo in parallel brakes terminal Oct 8, 2023
@sylv-io
Copy link
Author

sylv-io commented Oct 8, 2023

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

@millert
Copy link
Collaborator

millert commented Oct 9, 2023

Can you check whether setting

Defaults !use_pty

in the sudoers file works around the problem?

@sylv-io
Copy link
Author

sylv-io commented Oct 9, 2023

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. 👍

@sylv-io
Copy link
Author

sylv-io commented Oct 9, 2023

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

@sylv-io sylv-io changed the title Asynchronous execution of sudo in parallel brakes terminal Asynchronous execution of sudo in parallel breaks terminal Oct 9, 2023
millert added a commit that referenced this issue Oct 17, 2023
1. Lock the terminal before tcgetattr/tcsetattr
2. Don't restore terminal settings if changed by another process
3. Don't set terminal to raw mode if it is already raw
GitHub issue #312
millert added a commit that referenced this issue Oct 17, 2023
@millert
Copy link
Collaborator

millert commented Oct 19, 2023

Fixed by fabb626

@millert millert closed this as completed Oct 19, 2023
@sylv-io
Copy link
Author

sylv-io commented Oct 20, 2023

Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants