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

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

Merged
Emyrk merged 1 commit intomainfromstevenmasley/deadlock_fetch
Jun 23, 2025

Conversation

Emyrk
Copy link
Member

@EmyrkEmyrk commentedJun 23, 2025
edited
Loading

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:

vardb database.Storecache:=files.NewFromStore(db)// db.InTx consumes a pg connectiondb.InTx(func(tx database.Store) {// If running 1 connection pool, this will block// until the tx is done. ! DEADLOCK !file,_:= cache.Acquire(...)})

@EmyrkGraphite App
Copy link
MemberAuthor

Emyrk commentedJun 23, 2025
edited
Loading

@EmyrkEmyrk marked this pull request as ready for reviewJune 23, 2025 02:47
@EmyrkEmyrkforce-pushed thestevenmasley/deadlock_fetch branch 2 times, most recently from353f193 to2a37b9bCompareJune 23, 2025 03:38
@EmyrkEmyrk requested a review fromaslilacJune 23, 2025 06:07
@EmyrkEmyrkforce-pushed thestevenmasley/deadlock_fetch branch from2a37b9b toa33fad3CompareJune 23, 2025 06:07
@EmyrkEmyrkforce-pushed thestevenmasley/parameters_to_preview branch from635c56b tob7985e3CompareJune 23, 2025 06:07
@EmyrkEmyrk requested a review fromCopilotJune 23, 2025 12:25
Copy link
Contributor

@CopilotCopilotAI left a 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
FileDescription
coderd/files/closer.goUpdated Acquire method signature to include a database parameter.
coderd/files/cache_test.goAdjusted test calls to use the new signature for Acquire.
coderd/files/cache.goChanged Acquire and prepare functions to accept db, and moved fetch logic to a package-level func.
coderd/dynamicparameters/render.goUpdated Acquire calls with db parameter for template and module file acquisition.
coderd/coderd.goReplaced 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) {

@EmyrkEmyrk changed the base branch fromstevenmasley/parameters_to_preview tographite-base/18490June 23, 2025 16:31
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 poollimit.
@EmyrkEmyrkforce-pushed thestevenmasley/deadlock_fetch branch from9245e87 to7349e1fCompareJune 23, 2025 16:32
@EmyrkEmyrkforce-pushed thegraphite-base/18490 branch from467aca3 to659b787CompareJune 23, 2025 16:32
@graphite-appgraphite-appbot changed the base branch fromgraphite-base/18490 tomainJune 23, 2025 16:32
@EmyrkEmyrkforce-pushed thestevenmasley/deadlock_fetch branch 2 times, most recently from043cd58 to37c71f1CompareJune 23, 2025 16:45
@EmyrkEmyrk merged commitc1b35bf intomainJun 23, 2025
35 checks passed
@EmyrkEmyrk deleted the stevenmasley/deadlock_fetch branchJune 23, 2025 16:58
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsJun 23, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

Copilot code reviewCopilotCopilot left review comments

@aslilacaslilacaslilac approved these changes

Assignees

@EmyrkEmyrk

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@Emyrk@aslilac

[8]ページ先頭

©2009-2025 Movatter.jp