Skip to content

Commit 80c81d8

Browse files
committed
feat(synth/vm): catch panics in sequential ops thread
1 parent 6fc9ebb commit 80c81d8

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

synthesizer/src/vm/helpers/sequential_op.rs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use crate::vm::*;
1717
use console::network::prelude::Network;
1818

19+
use snarkvm_utilities::catch_unwind;
20+
1921
use std::{fmt, thread};
2022
use tokio::sync::oneshot;
2123

@@ -29,25 +31,32 @@ impl<N: Network, C: ConsensusStorage<N>> VM<N, C> {
2931
// Spawn a dedicated thread.
3032
let vm = self.clone();
3133
thread::spawn(move || {
32-
// Sequentially process incoming operations.
33-
while let Ok(request) = request_rx.recv() {
34-
let SequentialOperationRequest { op, response_tx } = request;
35-
debug!("Sequentially processing operation '{op}'");
36-
37-
// Perform the queued operation.
38-
let ret = match op {
39-
SequentialOperation::AddNextBlock(block) => {
40-
let ret = vm.add_next_block_inner(block);
41-
SequentialOperationResult::AddNextBlock(ret)
42-
}
43-
SequentialOperation::AtomicSpeculate(a, b, c, d, e, f) => {
44-
let ret = vm.atomic_speculate_inner(a, b, c, d, e, f);
45-
SequentialOperationResult::AtomicSpeculate(ret)
46-
}
47-
};
48-
49-
// Relay the results of the operation to the caller.
50-
let _ = response_tx.send(ret);
34+
let result = catch_unwind(move || {
35+
// Sequentially process incoming operations.
36+
while let Ok(request) = request_rx.recv() {
37+
let SequentialOperationRequest { op, response_tx } = request;
38+
debug!("Sequentially processing operation '{op}'");
39+
40+
// Perform the queued operation.
41+
let ret = match op {
42+
SequentialOperation::AddNextBlock(block) => {
43+
let ret = vm.add_next_block_inner(block);
44+
SequentialOperationResult::AddNextBlock(ret)
45+
}
46+
SequentialOperation::AtomicSpeculate(a, b, c, d, e, f) => {
47+
let ret = vm.atomic_speculate_inner(a, b, c, d, e, f);
48+
SequentialOperationResult::AtomicSpeculate(ret)
49+
}
50+
};
51+
52+
// Relay the results of the operation to the caller.
53+
let _ = response_tx.send(ret);
54+
}
55+
});
56+
57+
if let Err((msg, backtrace)) = result {
58+
error!("Sequential ops thread encountered a fatal error: {msg}");
59+
error!("Backtrace: {backtrace:?}");
5160
}
5261
})
5362
}

0 commit comments

Comments
 (0)