From fa0594f54b099996df3fd7811587d5411dc17e91 Mon Sep 17 00:00:00 2001 From: Sean Harger Date: Mon, 6 Aug 2018 14:22:31 -0700 Subject: [PATCH] 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. --- terminal.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terminal.go b/terminal.go index 1078631..bef988b 100644 --- a/terminal.go +++ b/terminal.go @@ -35,6 +35,7 @@ func NewTerminal(cfg *Config) (*Terminal, error) { sizeChan: make(chan string, 1), } + t.wg.Add(1) go t.ioloop() return t, nil } @@ -116,7 +117,6 @@ func (t *Terminal) KickRead() { } func (t *Terminal) ioloop() { - t.wg.Add(1) defer func() { t.wg.Done() close(t.outchan)