Skip to content
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

store: fix deadlock caused by conflicting lock order #213

Merged
merged 1 commit into from
Jun 7, 2020

Conversation

BurtonQin
Copy link
Contributor

GRAPH_POOL is locked before GRAPH_CONSOLIDATE at L102 and L103, L961 and L961

sonic/src/store/fst.rs

Lines 102 to 103 in fd7a21b

GRAPH_POOL.read().unwrap().len(),
GRAPH_CONSOLIDATE.read().unwrap().len(),

sonic/src/store/fst.rs

Lines 960 to 961 in fd7a21b

GRAPH_POOL.write().unwrap(),
GRAPH_CONSOLIDATE.write().unwrap(),

However, their lock order reverses at L200 and L203.

sonic/src/store/fst.rs

Lines 200 to 203 in fd7a21b

let graph_consolidate_read = GRAPH_CONSOLIDATE.read().unwrap();
for key in &*graph_consolidate_read {
if let Some(store) = GRAPH_POOL.read().unwrap().get(&key) {

This may cause a deadlock:

Thread-A Thread-B
A.lock()
B.lock()
B.lock()//deadlock!
A.lock()//deadlock!

The patch is to enforce the order for the two locks.

Signed-off-by: BurtonQin <bobbqqin@gmail.com>
@valeriansaliou valeriansaliou merged commit c616e75 into valeriansaliou:master Jun 7, 2020
@valeriansaliou
Copy link
Owner

Looks good, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants