Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 924ed0c

Browse files
committed
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.
1 parent 5ef59e7 commit 924ed0c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

.github/workflows/coder.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,11 @@ jobs:
150150
terraform_wrapper: false
151151

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

157159
- name: Upload DataDog Trace
158160
if: (success() || failure()) && github.actor != 'dependabot[bot]'
@@ -166,7 +168,7 @@ jobs:
166168
if: runner.os == 'Linux'
167169
run: DB=true gotestsum --junitfile="gotests.xml" --packages="./..." --
168170
-covermode=atomic -coverprofile="gotests.coverage" -timeout=3m
169-
-count=1 -race -parallel=2
171+
-count=1 -race -parallel=2 -failfast
170172

171173
- name: Upload DataDog Trace
172174
if: (success() || failure()) && github.actor != 'dependabot[bot]'

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+
return ctx
68+
}
69+
srv.Start()
6370
serverURL, err := url.Parse(srv.URL)
6471
require.NoError(t, err)
6572
t.Cleanup(srv.Close)

0 commit comments

Comments
 (0)