Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR is a fix for prometheus#3682. In some instances,
mem.Alerts.Subscribe()
andstore.gc()
can get deadlockedstore.Alerts.gc()
:store.Alerts.gc()
acquires a lock on its internal mutexstore.Alerts.mtx
mem.Alerts.mtx
mem.Alerts.Subscribe()
acquires a lock on its internal mutexmem.Alerts.mtx
and callsstore.Alerts.List()
mem.Alerts.mtx
. However this lock is already being held bymem.Subscribe()
mem.Subscribe()
cannot proceed becausestore.List()
cannot acquire lock (store.Alerts.mtx
) because it is being held bystore.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 becauseSubscribe()
was holding the lock.Subscribe()
cannot progress because it callsstore.Alerts.List()
which was waiting for lock acquisition which was being held bystore.Alerts.gc()
. This fix releases the lock held bystore.Alerts.gc()
prior to calling the callback function