mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #21018 from hqhq/hq_fix_race_exec_tty
Fix race condition when exec with tty
This commit is contained in:
commit
790d8f8520
2 changed files with 7 additions and 5 deletions
|
@ -441,12 +441,12 @@ type TtyConsole struct {
|
|||
}
|
||||
|
||||
// NewTtyConsole returns a new TtyConsole struct.
|
||||
func NewTtyConsole(console libcontainer.Console, pipes *execdriver.Pipes) (*TtyConsole, error) {
|
||||
func NewTtyConsole(console libcontainer.Console, pipes *execdriver.Pipes, wg *sync.WaitGroup) (*TtyConsole, error) {
|
||||
tty := &TtyConsole{
|
||||
console: console,
|
||||
}
|
||||
|
||||
if err := tty.AttachPipes(pipes); err != nil {
|
||||
if err := tty.AttachPipes(pipes, wg); err != nil {
|
||||
tty.Close()
|
||||
return nil, err
|
||||
}
|
||||
|
@ -460,8 +460,10 @@ func (t *TtyConsole) Resize(h, w int) error {
|
|||
}
|
||||
|
||||
// AttachPipes attaches given pipes to TtyConsole
|
||||
func (t *TtyConsole) AttachPipes(pipes *execdriver.Pipes) error {
|
||||
func (t *TtyConsole) AttachPipes(pipes *execdriver.Pipes, wg *sync.WaitGroup) error {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
if wb, ok := pipes.Stdout.(interface {
|
||||
CloseWriters() error
|
||||
}); ok {
|
||||
|
@ -501,7 +503,7 @@ func setupPipes(container *configs.Config, processConfig *execdriver.ProcessConf
|
|||
if err != nil {
|
||||
return writers, err
|
||||
}
|
||||
term, err := NewTtyConsole(cons, pipes)
|
||||
term, err := NewTtyConsole(cons, pipes, wg)
|
||||
if err != nil {
|
||||
return writers, err
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ func (s *DockerSuite) TestExecTTY(c *check.C) {
|
|||
c.Assert(err, checker.IsNil)
|
||||
defer p.Close()
|
||||
|
||||
_, err = p.Write([]byte("cat /foo && sleep 2 && exit\n"))
|
||||
_, err = p.Write([]byte("cat /foo && exit\n"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
chErr := make(chan error)
|
||||
|
|
Loading…
Reference in a new issue