fix: clean up idle http conns on wsconncache close (#6471)

See https://github.com/coder/coder/actions/runs/4346769070/jobs/7593243836
This commit is contained in:
Kyle Carberry
2023-03-06 20:45:49 -06:00
committed by GitHub
parent e0137bcff1
commit cf75d7e1fb
2 changed files with 4 additions and 3 deletions
+1
View File
@@ -121,6 +121,7 @@ func (c *Cache) Acquire(r *http.Request, id uuid.UUID) (*Conn, func(), error) {
}
c.connMap.Delete(id.String())
c.connGroup.Forget(id.String())
transport.CloseIdleConnections()
_ = conn.Close()
}()
return conn, nil
+3 -3
View File
@@ -126,15 +126,15 @@ func TestCache(t *testing.T) {
Host: fmt.Sprintf("127.0.0.1:%d", tcpAddr.Port),
Path: "/",
})
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
defer cancel()
req := httptest.NewRequest(http.MethodGet, "/", nil)
req = req.WithContext(ctx)
conn, release, err := cache.Acquire(req, uuid.Nil)
if !assert.NoError(t, err) {
return
}
defer release()
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
defer cancel()
if !conn.AwaitReachable(ctx) {
t.Error("agent not reachable")
return