From 4f7725c87c4ba478fd7312aab0460545bd2adbb4 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Tue, 7 Mar 2023 01:56:32 +0000 Subject: [PATCH] fix: clean up idle http conns on wsconncache close See https://github.com/coder/coder/actions/runs/4346769070/jobs/7593243836 --- coderd/wsconncache/wsconncache.go | 1 + coderd/wsconncache/wsconncache_test.go | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/coderd/wsconncache/wsconncache.go b/coderd/wsconncache/wsconncache.go index 63e939955045c..436581858cf4e 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 b74b142a84088..6abc5609ec6dc 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