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 for deadlock issue #3682 #2

Open
wants to merge 1 commit into
base: release-2024-2-6
Choose a base branch
from

Conversation

rajagopalanand
Copy link

@rajagopalanand rajagopalanand commented Feb 15, 2024

What does this PR do?

This PR is a fix for prometheus#3682. In some instances, mem.Alerts.Subscribe() and store.gc() can get deadlocked

  1. Lock acquisition in store.Alerts.gc():
    • The method store.Alerts.gc() acquires a lock on its internal mutex store.Alerts.mtx
    • While holding the lock, it then calls the callback function which will try to acquire a lock on mem.Alerts.mtx
  2. Concurrent Execution:
    • mem.Alerts.Subscribe() acquires a lock on its internal mutex mem.Alerts.mtx and calls store.Alerts.List()
  3. Deadlock situation:
    • Callback function tries to acquire a lock on mem.Alerts.mtx. However this lock is already being held by mem.Subscribe()
    • Similarly mem.Subscribe() cannot proceed because store.List() cannot acquire lock (store.Alerts.mtx) because it is being held by store.gc()

Another way of summarizing this is store.Alerts.gc() was holding the lock until callback function completed which in turn was waiting to acquire the lock. Callback function could not acquire the lock because Subscribe() was holding the lock. Subscribe() cannot progress because it calls store.Alerts.List() which was waiting for lock acquisition which was being held by store.Alerts.gc(). This fix releases the lock held by store.Alerts.gc() prior to calling the callback function

AM_Deadlock

Copy link

@emanlodovice emanlodovice left a comment

Choose a reason for hiding this comment

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

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants