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

Skip to content

Commit cf75d7e

Browse files
authored
fix: clean up idle http conns on wsconncache close (#6471)
See https://github.com/coder/coder/actions/runs/4346769070/jobs/7593243836
1 parent e0137bc commit cf75d7e

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

coderd/wsconncache/wsconncache.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ func (c *Cache) Acquire(r *http.Request, id uuid.UUID) (*Conn, func(), error) {
121121
}
122122
c.connMap.Delete(id.String())
123123
c.connGroup.Forget(id.String())
124+
transport.CloseIdleConnections()
124125
_ = conn.Close()
125126
}()
126127
return conn, nil

coderd/wsconncache/wsconncache_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,15 @@ func TestCache(t *testing.T) {
126126
Host: fmt.Sprintf("127.0.0.1:%d", tcpAddr.Port),
127127
Path: "/",
128128
})
129+
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
130+
defer cancel()
129131
req := httptest.NewRequest(http.MethodGet, "/", nil)
132+
req = req.WithContext(ctx)
130133
conn, release, err := cache.Acquire(req, uuid.Nil)
131134
if !assert.NoError(t, err) {
132135
return
133136
}
134137
defer release()
135-
136-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
137-
defer cancel()
138138
if !conn.AwaitReachable(ctx) {
139139
t.Error("agent not reachable")
140140
return

0 commit comments

Comments
 (0)