Fix deadlock error

This commit is contained in:
onyinyang 2024-02-05 15:59:16 -05:00
parent dae68efaae
commit b771a40a3d
No known key found for this signature in database
GPG Key ID: 156A6435430C2036
1 changed files with 14 additions and 20 deletions

View File

@ -194,16 +194,12 @@ impl LoxServerContext {
accounted_for_bridges,
);
}
let mut ba_clone = self.ba.lock().unwrap();
let total_reachable = ba_clone.bridge_table.reachable.len();
match total_reachable.cmp(&accounted_for_bridges.len()) {
Ordering::Greater => {
let unaccounted_for = ba_clone.find_and_remove_unaccounted_for_bridges(accounted_for_bridges);
for bridgeline in unaccounted_for {
match self.replace_with_new(bridgeline) {
lox_library::ReplaceSuccess::Replaced => {
println!("BridgeLine {:?} not found in rdsys update was successfully replaced.", bridgeline.uid_fingerprint);
self.metrics.removed_bridges.inc();
let unaccounted_for = self.ba.lock().unwrap().find_and_remove_unaccounted_for_bridges(accounted_for_bridges);
for bridgeline in unaccounted_for {
match self.replace_with_new(bridgeline) {
lox_library::ReplaceSuccess::Replaced => {
println!("BridgeLine {:?} not found in rdsys update was successfully replaced.", bridgeline.uid_fingerprint);
self.metrics.removed_bridges.inc();
}
lox_library::ReplaceSuccess::NotReplaced => {
// Try again to replace at the next update (nothing changes in the Lox Authority)
@ -217,18 +213,13 @@ impl LoxServerContext {
),
}
}
}
Ordering::Less => println!("Something unexpected occurred: The number of reachable bridges should not be less than those updated from rdsys"),
_ => (),
}
// Finally, assign any extra_bridges to new buckets if there are enough
while self.extra_bridges.lock().unwrap().len() >= MAX_BRIDGES_PER_BUCKET {
let bucket = self.remove_extra_bridges();
// TODO: Decide the circumstances under which a bridge is allocated to an open_inv or spare bucket,
// eventually also do some more fancy grouping of new resources, i.e., by type or region
let mut db_obj = self.db.lock().unwrap();
match ba_clone.add_spare_bucket(bucket, &mut db_obj) {
match self.ba.lock().unwrap().add_spare_bucket(bucket, &mut db_obj) {
Ok(_) => (),
Err(e) => {
println!("Error: {:?}", e);
@ -238,6 +229,9 @@ impl LoxServerContext {
}
}
}
// Any remaining extra bridges should be cleared from the Lox Context after each sync
// Currently bridgetable updating behaviour does not occur without receiving a resource list
// from rdsys so if the extra bridge is still working, it can be added to the table later
self.extra_bridges.lock().unwrap().clear();
}
@ -803,10 +797,10 @@ mod tests {
reachable_expected_length,
"Unexpected number of reachable bridges"
);
assert_eq!(
th.context.extra_bridges.lock().unwrap().len(),
0,
"Unexpected number of extra bridges"
// Extra bridges should be cleared from the Lox Context after each sync
assert!(
th.context.extra_bridges.lock().unwrap().is_empty(),
"Extra bridges should be empty after syncUnexpected number of extra bridges"
);
}