Open
Description
Problem 🐞
There is a possible scenario when using the graph.SimpleGraph
structure that might lead to a deadlock!
Let me explain
SimpleGraph.Adj
takes a mutex.RLock().- Under the hood,
SimpleGraph.Degree
is 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