mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
fix: Leaking yamux session after HTTP handler is closed (#329)
* fix: Leaking yamux session after HTTP handler is closed Closes #317. The httptest server cancels the context after the connection is closed, but if a connection takes a long time to close, the request would never end. This applies a context to the entire listener that cancels on test cleanup. After discussion with @bryphe-coder, reducing the parallel limit on Windows is likely to reduce failures as well. * Switch to windows-2022 to improve decompression * Invalidate cache on matrix OS
This commit is contained in:
@@ -6,6 +6,7 @@ package pty
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/creack/pty"
|
||||
)
|
||||
@@ -23,6 +24,7 @@ func newPty() (PTY, error) {
|
||||
}
|
||||
|
||||
type otherPty struct {
|
||||
mutex sync.Mutex
|
||||
pty, tty *os.File
|
||||
}
|
||||
|
||||
@@ -41,6 +43,8 @@ func (p *otherPty) Output() io.ReadWriter {
|
||||
}
|
||||
|
||||
func (p *otherPty) Resize(cols uint16, rows uint16) error {
|
||||
p.mutex.Lock()
|
||||
defer p.mutex.Unlock()
|
||||
return pty.Setsize(p.tty, &pty.Winsize{
|
||||
Rows: rows,
|
||||
Cols: cols,
|
||||
@@ -48,6 +52,9 @@ func (p *otherPty) Resize(cols uint16, rows uint16) error {
|
||||
}
|
||||
|
||||
func (p *otherPty) Close() error {
|
||||
p.mutex.Lock()
|
||||
defer p.mutex.Unlock()
|
||||
|
||||
err := p.pty.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
+6
-2
@@ -8,13 +8,17 @@ import (
|
||||
"syscall"
|
||||
|
||||
"github.com/creack/pty"
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
func startPty(cmd *exec.Cmd) (PTY, error) {
|
||||
ptty, tty, err := pty.Open()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, xerrors.Errorf("open: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
_ = tty.Close()
|
||||
}()
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
Setsid: true,
|
||||
Setctty: true,
|
||||
@@ -25,7 +29,7 @@ func startPty(cmd *exec.Cmd) (PTY, error) {
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
_ = ptty.Close()
|
||||
return nil, err
|
||||
return nil, xerrors.Errorf("start: %w", err)
|
||||
}
|
||||
return &otherPty{
|
||||
pty: ptty,
|
||||
|
||||
Reference in New Issue
Block a user