- Notifications
You must be signed in to change notification settings - Fork1.1k
chore: use database in current context for file cache#18490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Emyrk commentedJun 23, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
This stack of pull requests is managed byGraphite. Learn more aboutstacking. |
353f193 to2a37b9bCompare2a37b9b toa33fad3Compare635c56b tob7985e3CompareThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Pull Request Overview
This PR updates the file cache implementation to use the current database context when acquiring files, thereby preventing potential deadlocks when running in a transaction. Key changes include:
- Updating the Acquire method signatures in files/closer.go, files/cache.go, and related files to accept an explicit database.Store parameter.
- Modifying tests in cache_test.go and other parts of the code to use the updated Acquire method.
- Removing the deprecated NewFromStore constructor and switching to the new New constructor in coderd/coderd.go.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| coderd/files/closer.go | Updated Acquire method signature to include a database parameter. |
| coderd/files/cache_test.go | Adjusted test calls to use the new signature for Acquire. |
| coderd/files/cache.go | Changed Acquire and prepare functions to accept db, and moved fetch logic to a package-level func. |
| coderd/dynamicparameters/render.go | Updated Acquire calls with db parameter for template and module file acquisition. |
| coderd/coderd.go | Replaced the deprecated NewFromStore with the new New constructor for FileCache. |
Comments suppressed due to low confidence (1)
coderd/files/cache.go:140
- Update the function documentation to reflect the addition of the db parameter and explain its role in avoiding deadlocks by providing the current database context.
func (c *Cache) Acquire(ctx context.Context, db database.Store, fileID uuid.UUID) (*CloseFS, error) {b7985e3 to467aca3Comparea33fad3 to9245e87CompareUsing the db.Store when in a TX causes a deadlock for dbmem.In production, this can cause a deadlock if at the current conn poollimit.
9245e87 to7349e1fCompare043cd58 to37c71f1Comparec1b35bf intomainUh oh!
There was an error while loading.Please reload this page.

Uh oh!
There was an error while loading.Please reload this page.
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.
Example: