Skip to content

Commit a782284

Browse files
authored
Merge branch 'develop' into fix/tenure-extend-no-sortition
2 parents dec06d7 + d11ed3c commit a782284

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2401
-3247
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
99

1010
### Changed
1111
- Add index for StacksBlockId to nakamoto block headers table (improves node performance)
12+
- Remove the panic for reporting DB deadlocks (just error and continue waiting)
1213

1314
## [3.0.0.0.0]
1415

stacks-common/src/util/db.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,25 @@ pub fn update_lock_table(conn: &Connection) {
5151
/// Called by `rusqlite` if we are waiting too long on a database lock
5252
/// If called too many times, will assume a deadlock and panic
5353
pub fn tx_busy_handler(run_count: i32) -> bool {
54-
const TIMEOUT: Duration = Duration::from_secs(300);
5554
const AVG_SLEEP_TIME_MS: u64 = 100;
5655

56+
// Every ~5min, report an error with a backtrace
57+
// 5min * 60s/min * 1_000ms/s / 100ms
58+
const ERROR_COUNT: u32 = 3_000;
59+
5760
// First, check if this is taking unreasonably long. If so, it's probably a deadlock
5861
let run_count = run_count.unsigned_abs();
59-
let approx_time_elapsed =
60-
Duration::from_millis(AVG_SLEEP_TIME_MS.saturating_mul(u64::from(run_count)));
61-
if approx_time_elapsed > TIMEOUT {
62-
error!("Deadlock detected. Waited {} seconds (estimated) for database lock. Giving up", approx_time_elapsed.as_secs();
62+
if run_count > 0 && run_count % ERROR_COUNT == 0 {
63+
error!("Deadlock detected. Waited 5 minutes (estimated) for database lock.";
6364
"run_count" => run_count,
6465
"backtrace" => ?Backtrace::capture()
6566
);
6667
for (k, v) in LOCK_TABLE.lock().unwrap().iter() {
6768
error!("Database '{k}' last locked by {v}");
6869
}
69-
panic!("Deadlock in thread {:?}", thread::current().name());
7070
}
7171

7272
let mut sleep_time_ms = 2u64.saturating_pow(run_count);
73-
7473
sleep_time_ms = sleep_time_ms.saturating_add(thread_rng().gen_range(0..sleep_time_ms));
7574

7675
if sleep_time_ms > AVG_SLEEP_TIME_MS {

stackslib/src/chainstate/stacks/tests/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,14 +475,14 @@ impl TestStacksNode {
475475
};
476476

477477
if StacksChainState::has_stored_block(
478-
&self.chainstate.db(),
478+
self.chainstate.db(),
479479
&self.chainstate.blocks_path,
480480
&consensus_hash,
481481
&bc.block_header_hash,
482482
)
483483
.unwrap()
484484
&& !StacksChainState::is_block_orphaned(
485-
&self.chainstate.db(),
485+
self.chainstate.db(),
486486
&consensus_hash,
487487
&bc.block_header_hash,
488488
)

stackslib/src/net/api/getattachmentsinv.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,10 @@ impl HttpRequest for RPCGetAttachmentsInvRequestHandler {
9696
if key == "index_block_hash" {
9797
index_block_hash = StacksBlockId::from_hex(&value).ok();
9898
} else if key == "pages_indexes" {
99-
if let Ok(pages_indexes_value) = value.parse::<String>() {
100-
for entry in pages_indexes_value.split(',') {
101-
if let Ok(page_index) = entry.parse::<u32>() {
102-
page_indexes.insert(page_index);
103-
}
99+
let pages_indexes_value = value.to_string();
100+
for entry in pages_indexes_value.split(',') {
101+
if let Ok(page_index) = entry.parse::<u32>() {
102+
page_indexes.insert(page_index);
104103
}
105104
}
106105
}

0 commit comments

Comments
 (0)