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

Skip to content

Commit b6e6d7b

Browse files
committed
Merge branch 'readclose' into apps
2 parents c57f8dd + 8e61cac commit b6e6d7b

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

coderd/wsconncache/wsconncache.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,14 @@ func (c *Cache) Acquire(r *http.Request, id uuid.UUID) (*Conn, func(), error) {
9090
go func() {
9191
select {
9292
case <-timeoutCtx.Done():
93-
_ = conn.CloseWithError(xerrors.New("cache timeout"))
9493
case <-conn.Closed():
9594
}
9695
c.connMutex.Lock()
9796
delete(c.conns, id)
9897
c.connMutex.Unlock()
98+
// This should close after the delete so callers
99+
// can check the `Closed()` channel for this to be expired.
100+
_ = conn.CloseWithError(xerrors.New("cache timeout"))
99101
}()
100102
c.connMutex.Lock()
101103
c.conns[id] = conn

provisionersdk/transport.go

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package provisionersdk
33
import (
44
"context"
55
"io"
6+
"sync"
67

78
"github.com/hashicorp/yamux"
89
"storj.io/drpc"
@@ -45,11 +46,14 @@ func Conn(session *yamux.Session) drpc.Conn {
4546
}
4647

4748
type readWriteCloser struct {
49+
closeMutex sync.Mutex
4850
io.ReadCloser
4951
io.WriteCloser
5052
}
5153

5254
func (c *readWriteCloser) Close() error {
55+
c.closeMutex.Lock()
56+
defer c.closeMutex.Unlock()
5357
err := c.ReadCloser.Close()
5458
if err != nil {
5559
return err

0 commit comments

Comments
 (0)