Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6126814

Browse files
committed
fix: Leaking yamux session after HTTP handler is closed
Closes#317. The httptest server cancels the context after the connectionis closed, but if a connection takes a long time to close, the requestwould never end. This applies a context to the entire listener that cancelson test cleanup.After discussion with@bryphe-coder, reducing the parallel limit onWindows is likely to reduce failures as well.
1 parent5ef59e7 commit6126814

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

‎.github/workflows/coder.yaml‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,12 @@ jobs:
150150
terraform_wrapper:false
151151

152152
-name:Test with Mock Database
153+
env:
154+
GOCOUNT:${{ runner.os == 'Windows' && 3 || 5 }}
155+
GOMAXPROCS:${{ runner.os == 'Windows' && 1 || 2 }}
153156
run:gotestsum --junitfile="gotests.xml" --packages="./..." --
154157
-covermode=atomic -coverprofile="gotests.coverage"
155-
-timeout=3m -count=5 -race -short -parallel=2
158+
-timeout=3m -count=$GOCOUNT -race -short -failfast
156159

157160
-name:Upload DataDog Trace
158161
if:(success() || failure()) && github.actor != 'dependabot[bot]'
@@ -166,10 +169,10 @@ jobs:
166169
if:runner.os == 'Linux'
167170
run:DB=true gotestsum --junitfile="gotests.xml" --packages="./..." --
168171
-covermode=atomic -coverprofile="gotests.coverage" -timeout=3m
169-
-count=1 -race -parallel=2
172+
-count=1 -race -parallel=2 -failfast
170173

171174
-name:Upload DataDog Trace
172-
if:(success() || failure()) && github.actor != 'dependabot[bot]'
175+
if:(success() || failure()) && github.actor != 'dependabot[bot]' && runner.os == 'Linux'
173176
env:
174177
DATADOG_API_KEY:${{ secrets.DATADOG_API_KEY }}
175178
DD_DATABASE:postgresql

‎coderd/coderdtest/coderdtest.go‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"database/sql"
66
"io"
7+
"net"
78
"net/http/httptest"
89
"net/url"
910
"os"
@@ -59,7 +60,13 @@ func New(t *testing.T) *codersdk.Client {
5960
Database:db,
6061
Pubsub:pubsub,
6162
})
62-
srv:=httptest.NewServer(handler)
63+
srv:=httptest.NewUnstartedServer(handler)
64+
srv.Config.BaseContext=func(_ net.Listener) context.Context {
65+
ctx,cancelFunc:=context.WithCancel(context.Background())
66+
t.Cleanup(cancelFunc)
67+
returnctx
68+
}
69+
srv.Start()
6370
serverURL,err:=url.Parse(srv.URL)
6471
require.NoError(t,err)
6572
t.Cleanup(srv.Close)

‎pty/pty_other.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package pty
66
import (
77
"io"
88
"os"
9+
"sync"
910

1011
"github.com/creack/pty"
1112
)
@@ -23,6 +24,7 @@ func newPty() (PTY, error) {
2324
}
2425

2526
typeotherPtystruct {
27+
mutex sync.Mutex
2628
pty,tty*os.File
2729
}
2830

@@ -41,13 +43,18 @@ func (p *otherPty) Output() io.ReadWriter {
4143
}
4244

4345
func (p*otherPty)Resize(colsuint16,rowsuint16)error {
46+
p.mutex.Lock()
47+
deferp.mutex.Unlock()
4448
returnpty.Setsize(p.tty,&pty.Winsize{
4549
Rows:rows,
4650
Cols:cols,
4751
})
4852
}
4953

5054
func (p*otherPty)Close()error {
55+
p.mutex.Lock()
56+
deferp.mutex.Unlock()
57+
5158
err:=p.pty.Close()
5259
iferr!=nil {
5360
returnerr

‎pty/start_other.go‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ import (
88
"syscall"
99

1010
"github.com/creack/pty"
11+
"golang.org/x/xerrors"
1112
)
1213

1314
funcstartPty(cmd*exec.Cmd) (PTY,error) {
1415
ptty,tty,err:=pty.Open()
1516
iferr!=nil {
16-
returnnil,err
17+
returnnil,xerrors.Errorf("open: %w",err)
1718
}
19+
deferfunc() {
20+
_=tty.Close()
21+
}()
1822
cmd.SysProcAttr=&syscall.SysProcAttr{
1923
Setsid:true,
2024
Setctty:true,
@@ -25,7 +29,7 @@ func startPty(cmd *exec.Cmd) (PTY, error) {
2529
err=cmd.Start()
2630
iferr!=nil {
2731
_=ptty.Close()
28-
returnnil,err
32+
returnnil,xerrors.Errorf("start: %w",err)
2933
}
3034
return&otherPty{
3135
pty:ptty,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp