Introduces a per-injection-point lock to avoid deadlocks #485
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.
We are observing some deadlocks in our project, mostly caused by a complex injection hierarchy. After some research, we concluded some possible injection paths can lead into it:
For instance, given the follow
Components:classDiagram Foundation <|-- Tracking Foundation <|-- Observability Foundation : +Logger logger Foundation : +Client httpClient Tracking : +TrackingService trackingService Observability : +ObservabilityService observabiltyServiceIf we initialize concurrently (in different threads) 2 classes that both require some injection from
TrackingandObservability, but in different order, then we'll have a deadlock on both trying to acquire a lock onFoundation's:We are proposing to introduce a per-injection-point lock (but still retaining the main lock in the component to mutate the
sharedInstancesmap) to avoid this situation.Note
This PR is based on #484, see here the real diff gmazzo/needle@simplify-component...fix-deadlock
In our real case,
ServiceAandServiceBarebootstrappingServiceanddevicesProfilingManager. This is the crash: