Fix a race condition in terminal.go

There is a race condition in terminal.go relating to wait groups. The wg.Add method should be called by the parent goroutine, not the child.

https://golang.org/pkg/sync/#WaitGroup

This was caught by gotsan.
This commit is contained in:
Sean Harger 2018-08-06 14:22:31 -07:00 committed by GitHub
parent 2972be24d4
commit fa0594f54b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View File

@ -35,6 +35,7 @@ func NewTerminal(cfg *Config) (*Terminal, error) {
sizeChan: make(chan string, 1), sizeChan: make(chan string, 1),
} }
t.wg.Add(1)
go t.ioloop() go t.ioloop()
return t, nil return t, nil
} }
@ -116,7 +117,6 @@ func (t *Terminal) KickRead() {
} }
func (t *Terminal) ioloop() { func (t *Terminal) ioloop() {
t.wg.Add(1)
defer func() { defer func() {
t.wg.Done() t.wg.Done()
close(t.outchan) close(t.outchan)