Skip to content

Commit 504189b

Browse files
authored
[supervisor] Fix race on terminal listener closing (#19774)
1 parent 72faa7c commit 504189b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

components/supervisor/pkg/terminal/terminal.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ func (l *multiWriterListener) CloseWithError(err error) error {
484484
if err != nil {
485485
l.closeErr = err
486486
}
487-
close(l.closeChan)
488487
l.closed = true
488+
close(l.closeChan)
489489

490490
// actual cleanup happens in a go routine started by Listen()
491491
})
@@ -561,17 +561,19 @@ func (mw *multiWriter) ListenWithOptions(options TermListenOptions) io.ReadClose
561561
go func() {
562562
// listener cleanup on close
563563
<-closeChan
564+
564565
if res.closeErr != nil {
565566
log.WithError(res.closeErr).Error("terminal listener droped out")
566567
w.CloseWithError(res.closeErr)
567568
} else {
568569
w.Close()
569570
}
570-
close(cchan)
571571

572572
mw.mu.Lock()
573+
defer mw.mu.Unlock()
574+
close(cchan)
575+
573576
delete(mw.listener, res)
574-
mw.mu.Unlock()
575577
}()
576578

577579
mw.listener[res] = struct{}{}

0 commit comments

Comments
 (0)