Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdf7acff

Browse files
committed
I win at debugging deadlocks today
1 parentec53459 commitdf7acff

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

‎coderd/files/cache.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ type cacheEntry struct {
114114
value*lazy.ValueWithError[CacheEntryValue]
115115

116116
closefunc()
117+
purgefunc()
117118
}
118119

119120
typeCacheEntryValuestruct {
@@ -149,7 +150,8 @@ func (c *Cache) Acquire(ctx context.Context, db database.Store, fileID uuid.UUID
149150
e:=c.prepare(db,fileID)
150151
ev,err:=e.value.Load()
151152
iferr!=nil {
152-
c.purge(fileID)
153+
e.close()
154+
e.purge()
153155
returnnil,err
154156
}
155157

@@ -193,9 +195,9 @@ func (c *Cache) prepare(db database.Store, fileID uuid.UUID) *cacheEntry {
193195
if!ok {
194196
hitLabel="false"
195197

196-
varreleaseOnce sync.Once
197-
release:=func() {
198-
releaseOnce.Do(func() {
198+
varpurgeOnce sync.Once
199+
purge:=func() {
200+
purgeOnce.Do(func() {
199201
c.purge(fileID)
200202
})
201203
}
@@ -204,10 +206,6 @@ func (c *Cache) prepare(db database.Store, fileID uuid.UUID) *cacheEntry {
204206
value:lazy.NewWithError(func() (CacheEntryValue,error) {
205207
val,err:=fetch(db,fileID)
206208
iferr!=nil {
207-
// Force future calls to Acquire to trigger a new fetch as soon as
208-
// a fetch has failed, even if references are still held.
209-
entry.close()
210-
release()
211209
returnval,err
212210
}
213211

@@ -228,8 +226,10 @@ func (c *Cache) prepare(db database.Store, fileID uuid.UUID) *cacheEntry {
228226
return
229227
}
230228

231-
release()
229+
purge()
232230
},
231+
232+
purge:purge,
233233
}
234234
c.data[fileID]=entry
235235

@@ -245,7 +245,8 @@ func (c *Cache) prepare(db database.Store, fileID uuid.UUID) *cacheEntry {
245245
returnentry
246246
}
247247

248-
// purge immediately removes an entry from the cache. It should be called
248+
// purge immediately removes an entry from the cache, even if it has open references.
249+
// It should only be called from the `close` function in a `cacheEntry`.
249250
func (c*Cache)purge(fileID uuid.UUID) {
250251
c.lock.Lock()
251252
deferc.lock.Unlock()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp