Skip to content

Commit f78c07a

Browse files
authored
Merge pull request Blockstream#68 from mempool/junderw/threadpool-builder-fix
ThreadPoolBuilder can fail when resources are busy
2 parents 13e5023 + 1cb2715 commit f78c07a

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/new_index/schema.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,11 +1095,23 @@ fn lookup_txos(
10951095
outpoints: &BTreeSet<OutPoint>,
10961096
allow_missing: bool,
10971097
) -> HashMap<OutPoint, TxOut> {
1098-
let pool = rayon::ThreadPoolBuilder::new()
1099-
.num_threads(16) // we need to saturate SSD IOPS
1100-
.thread_name(|i| format!("lookup-txo-{}", i))
1101-
.build()
1102-
.unwrap();
1098+
let mut loop_count = 10;
1099+
let pool = loop {
1100+
match rayon::ThreadPoolBuilder::new()
1101+
.num_threads(16) // we need to saturate SSD IOPS
1102+
.thread_name(|i| format!("lookup-txo-{}", i))
1103+
.build()
1104+
{
1105+
Ok(pool) => break pool,
1106+
Err(e) => {
1107+
if loop_count == 0 {
1108+
panic!("schema::lookup_txos failed to create a ThreadPool: {}", e);
1109+
}
1110+
std::thread::sleep(std::time::Duration::from_millis(50));
1111+
loop_count -= 1;
1112+
}
1113+
}
1114+
};
11031115
pool.install(|| {
11041116
outpoints
11051117
.par_iter()

0 commit comments

Comments
 (0)