After verifying with the Tokio docs, RwLock is write-preferring, which can lead to a deadlock if the following occurs:
- We currently hold a read handle to a global state in Function A.
- An event is triggered which causes Function B to fire, which requests a write handle (enters waiting state).
- Function A calls another function which, in turn, also requests another read handle.
The second read handle in this example will never be granted, as it is waiting until Function B's write handle is granted. This, in turn, means Function A never finishes (and probably doesn't drop its read handle as a result), hence causing deadlock.
Need to do a pass over the code to ensure every function only ever holds a single handle at a time (including any function calls), which should avoid this issue from occurring...
After verifying with the Tokio docs,
RwLockis write-preferring, which can lead to a deadlock if the following occurs:The second read handle in this example will never be granted, as it is waiting until Function B's write handle is granted. This, in turn, means Function A never finishes (and probably doesn't drop its read handle as a result), hence causing deadlock.
Need to do a pass over the code to ensure every function only ever holds a single handle at a time (including any function calls), which should avoid this issue from occurring...