diff --git a/coderd/wsconncache/wsconncache.go b/coderd/wsconncache/wsconncache.go index 63e9399550..436581858c 100644 --- a/coderd/wsconncache/wsconncache.go +++ b/coderd/wsconncache/wsconncache.go @@ -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 diff --git a/coderd/wsconncache/wsconncache_test.go b/coderd/wsconncache/wsconncache_test.go index b74b142a84..6abc5609ec 100644 --- a/coderd/wsconncache/wsconncache_test.go +++ b/coderd/wsconncache/wsconncache_test.go @@ -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