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

Skip to content

Commit 72f1b74

Browse files
committed
set cache to nil to signal closed
1 parent 7555cff commit 72f1b74

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

coderd/files/closer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ type CacheCloser struct {
1515

1616
closers []func()
1717
mu sync.Mutex
18-
closed bool
1918
}
2019

2120
func NewCacheCloser(cache FileAcquirer) *CacheCloser {
@@ -32,8 +31,9 @@ func (c *CacheCloser) Close() {
3231
for _, doClose := range c.closers {
3332
doClose()
3433
}
35-
c.closed = true
3634

35+
// Prevent further acquisitions
36+
c.cache = nil
3737
// Remove any references
3838
c.closers = make([]func(), 0)
3939
}
@@ -42,7 +42,7 @@ func (c *CacheCloser) Acquire(ctx context.Context, fileID uuid.UUID) (*CloseFS,
4242
c.mu.Lock()
4343
defer c.mu.Unlock()
4444

45-
if c.closed {
45+
if c.cache == nil {
4646
return nil, xerrors.New("cache is closed, and cannot acquire new files")
4747
}
4848

0 commit comments

Comments
 (0)