-
Notifications
You must be signed in to change notification settings - Fork 398
fix(processmanager): race during release resources #899
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
Closed
korniltsev-grafanista
wants to merge
2
commits into
open-telemetry:main
from
grafana:pm-release-resources-race
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There 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.
I'm wondering if this additional mutex might introduce a potential deadlock. Introduction the function
releaseResources()and using the global processmanager lock should be sufficient, shouldn't it?As far as I can tell, MapFileIDMapper is used only in the scope of processmanager - except for coredumps. So to prevent potential deadlocks, maybe just use the processmanager lock?
There 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.
I don't see how this can deadlock. Let me try understand this
Uh oh!
There was an error while loading. Please reload this page.
There 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.
It is not.
FileIDMapper.Getis called from the trace handling goroutine under no lock. andFileIDMapper.Setis called from another goroutine, also under no lock.In practice the synchronization happens inside of
type lruFileIDMapper struct { cache *lru.SyncedLRU[host.FileID, libpf.FrameMappingFile]}.The
MapFileIDMapperis only used in tests and with this PR the synchronization also happens inside the implementation of the interface, same way as in LRU implementation.There 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.
@florianl do you mind explaining a bit further what deadlock do you have in mind? I could not fathom this
There 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.
For the scenario, where this package runs as part of ebpf-profiler, the deadlock is limited (assuming we catch it in review). But as the FileIDMapper interface and its implementations are public, nothing stops external parties from interacting with it. So making the API more private, could be a first step.
And to make sure, accessing lurFileIDMapper is safe, we could just switch to ShardedLRU instead of SyncedLRU. With the type switch we would also make sure, that changes to the lruFileIDMapper implementation stay safe to use, and sync.Mutex does not need to be called explicitly.
There 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.
At the moment there is no deadlock in ebpf-profiler. But there is a limited risk for a deadlock if processmanager evolves and the FileIDMapper lock is hold before the procressmanager lock is fetched. But as stated, this could be hopefully identified in a review.
The risk for a deadlock is different for elements that import and use this package. They can directly interact (via Get and Set) with FileIDMapper. For that reason I suggest to limit the API and lock it down
There 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.
Do note that #749 will remove the fileidmapper completely.
There 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.
I am also working to remove the ReleaseResources stage.
There 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.
And #909 removes the
ReleaseResourcesstage.There 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.
NIce, I will just close this one