-
Notifications
You must be signed in to change notification settings - Fork 845
Open
Description
Problem π
There is a possible scenario when using the graph.SimpleGraph structure that might lead to a deadlock!
Let me explain
SimpleGraph.Adjtakes a mutex.RLock().- Under the hood,
SimpleGraph.Degreeis called, which also takesmutex.RLock(). - If
mutex.Lock()is called between the 2 stages above (usingSimpleGraph.AddEdge), then both functions get blocked forever.
A simple block of code demonstrates this issue (time.Sleep() is used to simulate the call order).
Solution β
- Create a sub function
SimpleGraph.degree()that doesn't useRLock()(similar toSimpleGraph.addVertex(). - Move code of
SimpleGraph.Degree()to the new function and leave onlyRLock()code.
Metadata
Metadata
Assignees
Labels
No labels