chore: use database in current context for file cache (#18490)

Using the db.Store when in a TX causes a deadlock for dbmem.
In production, this can cause a deadlock if at the current conn pool
limit.
This commit is contained in:
Steven Masley
2025-06-23 11:58:52 -05:00
committed by GitHub
parent 659b787b9f
commit c1b35bf2f6
5 changed files with 62 additions and 63 deletions
+4 -2
View File
@@ -6,6 +6,8 @@ import (
"github.com/google/uuid"
"golang.org/x/xerrors"
"github.com/coder/coder/v2/coderd/database"
)
// CacheCloser is a cache wrapper used to close all acquired files.
@@ -38,7 +40,7 @@ func (c *CacheCloser) Close() {
c.closers = nil
}
func (c *CacheCloser) Acquire(ctx context.Context, fileID uuid.UUID) (*CloseFS, error) {
func (c *CacheCloser) Acquire(ctx context.Context, db database.Store, fileID uuid.UUID) (*CloseFS, error) {
c.mu.Lock()
defer c.mu.Unlock()
@@ -46,7 +48,7 @@ func (c *CacheCloser) Acquire(ctx context.Context, fileID uuid.UUID) (*CloseFS,
return nil, xerrors.New("cache is closed, and cannot acquire new files")
}
f, err := c.cache.Acquire(ctx, fileID)
f, err := c.cache.Acquire(ctx, db, fileID)
if err != nil {
return nil, err
}