Skip to content

Commit

Permalink
fix(conpty): close the pseudo console only once
Browse files Browse the repository at this point in the history
Apparently, for reasons unknown, closing the pseudo console more than
once causes the parent process to be killed as well.

This should fix it for now, no idea why it happens though.

Signed-off-by: Carlos Alexandro Becker <[email protected]>
  • Loading branch information
caarlos0 committed Jan 30, 2024
1 parent 0ee7136 commit 2071614
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions exp/term/windows/conpty/conpty_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"os"
"sync"
"syscall"
"unsafe"

Expand All @@ -28,6 +29,7 @@ type ConPty struct {
inPipe, outPipe *os.File
attrList *windows.ProcThreadAttributeListContainer
size windows.Coord
closeOnce sync.Once
}

var (
Expand Down Expand Up @@ -106,8 +108,9 @@ func (p *ConPty) Close() error {
if p.attrList != nil {
p.attrList.Delete()
}

windows.ClosePseudoConsole(*p.hpc)
p.closeOnce.Do(func() {
windows.ClosePseudoConsole(*p.hpc)
})
return errors.Join(p.inPipe.Close(), p.outPipe.Close())
}

Expand Down

0 comments on commit 2071614

Please sign in to comment.