Skip to content

Commit 87b5113

Browse files
committed
Fix conn cache
1 parent 9ee60d6 commit 87b5113

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

coderd/wsconncache/wsconncache.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,12 @@ func (c *Cache) Acquire(r *http.Request, id uuid.UUID) (*Conn, func(), error) {
8686
// A singleflight group is used to allow for concurrent requests to the
8787
// same identifier to resolve.
8888
rawConn, err, _ = c.connGroup.Do(id.String(), func() (interface{}, error) {
89+
c.closeMutex.Lock()
90+
c.closeGroup.Add(1)
91+
c.closeMutex.Unlock()
8992
agentConn, err := c.dialer(r, id)
9093
if err != nil {
94+
c.closeGroup.Done()
9195
return nil, xerrors.Errorf("dial: %w", err)
9296
}
9397
timeoutCtx, timeoutCancelFunc := context.WithCancel(context.Background())
@@ -102,9 +106,6 @@ func (c *Cache) Acquire(r *http.Request, id uuid.UUID) (*Conn, func(), error) {
102106
timeoutCancel: timeoutCancelFunc,
103107
transport: transport,
104108
}
105-
c.closeMutex.Lock()
106-
c.closeGroup.Add(1)
107-
c.closeMutex.Unlock()
108109
go func() {
109110
defer c.closeGroup.Done()
110111
var err error

0 commit comments

Comments
 (0)