Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid acquiring lock on two mutexes at the same time to prevent deadlock #13636

Merged
merged 1 commit into from
May 18, 2023

Conversation

alexmt
Copy link
Collaborator

@alexmt alexmt commented May 17, 2023

Closes #11458

PR fixes an almost identical bug that was fixed by argoproj/gitops-engine#521.

Deadlock is happening because we have two functions that acquire lock on two different mutexes in different order.

Function 1 stack trace:

Function 2 stack trace:

So liveStateCache.invalidate waits for SetPopulateResourceInfoHandler and SetPopulateResourceInfoHandler waits for liveStateCache.invalidate.

PR updates liveStateCache.invalidate to release Mutex 1 before it locks Mutex 2

@alexmt alexmt requested a review from jessesuen May 17, 2023 23:33
Copy link
Member

@jessesuen jessesuen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep this looks like another one. Great job!

@codecov
Copy link

codecov bot commented May 17, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (f61f94f) 49.24% compared to head (cb653f1) 49.24%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #13636   +/-   ##
=======================================
  Coverage   49.24%   49.24%           
=======================================
  Files         248      248           
  Lines       42838    42839    +1     
=======================================
+ Hits        21094    21097    +3     
+ Misses      19646    19645    -1     
+ Partials     2098     2097    -1     
Impacted Files Coverage Δ
controller/cache/cache.go 26.29% <0.00%> (-0.06%) ⬇️

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

…deadlock

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
@alexmt alexmt force-pushed the invalidate-settings-lock branch from 99cb45f to cb653f1 Compare May 18, 2023 18:27
@alexmt alexmt enabled auto-merge (squash) May 18, 2023 18:28
@alexmt alexmt merged commit 325878c into argoproj:master May 18, 2023
@alexmt alexmt deleted the invalidate-settings-lock branch May 18, 2023 19:20
@alexmt alexmt added cherry-pick/2.5 cherry-pick/2.6 cherry-pick/2.7 Candidate for cherry picking into the 2.7 release branch labels May 18, 2023
@alexmt
Copy link
Collaborator Author

alexmt commented May 18, 2023

/cherry-pick release-2.7

1 similar comment
@crenshaw-dev
Copy link
Member

/cherry-pick release-2.7

gcp-cherry-pick-bot bot pushed a commit that referenced this pull request May 18, 2023
…deadlock (#13636)

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
@alexmt
Copy link
Collaborator Author

alexmt commented May 18, 2023

/cherry-pick release-2.6

1 similar comment
@alexmt
Copy link
Collaborator Author

alexmt commented May 18, 2023

/cherry-pick release-2.6

gcp-cherry-pick-bot bot pushed a commit that referenced this pull request May 18, 2023
…deadlock (#13636)

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
@alexmt
Copy link
Collaborator Author

alexmt commented May 18, 2023

/cherry-pick release-2.5

gcp-cherry-pick-bot bot pushed a commit that referenced this pull request May 18, 2023
…deadlock (#13636)

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
alexmt added a commit that referenced this pull request May 18, 2023
…deadlock (#13636) (#13649)

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
Co-authored-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
alexmt added a commit that referenced this pull request May 18, 2023
…deadlock (#13636) (#13650)

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
Co-authored-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
alexmt added a commit that referenced this pull request May 18, 2023
…deadlock (#13636) (#13648)

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
Co-authored-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
@agaudreault
Copy link
Member

agaudreault commented Jun 14, 2023

Closes #4044 #10842

schakrad pushed a commit to schakrad/argo-cd that referenced this pull request Jul 24, 2023
…deadlock (argoproj#13636) (argoproj#13648)

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
Co-authored-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
Signed-off-by: schakrad <58915923+schakrad@users.noreply.github.com>
yyzxw pushed a commit to yyzxw/argo-cd that referenced this pull request Aug 9, 2023
…deadlock (argoproj#13636)

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick/2.5 cherry-pick/2.6 cherry-pick/2.7 Candidate for cherry picking into the 2.7 release branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

argocd applicationcontroller stops working/syncing
4 participants